0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

UITableViewCellの中のUIImageVewでアニメーションすると勝手に止まる件

Posted at

UITableView の中に UIImageView を入れていて、その UIImageViewanimationImages を指定してアニメーションを表示している時、テーブルのセルを選択するとアニメーションが止まってしまう。

解決法

setSelected, setHighlightedをオーバーライドしてその中でアニメーションを再開する。

class MyCell: UITableViewCell {

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        restartAnimatingIfNeeded()
    }

    override func setHighlighted(_ highlighted: Bool, animated: Bool) {
        super.setHighlighted(highlighted, animated: animated)
        restartAnimatingIfNeeded()
    }

    func restartAnimatingIfNeeded() {
        if imageView.animationImages != nil {
            imageView.startAnimating()
        }
    }
}

少々無理やりな気がするけど…あと最初のフレームから再生されてしまうのも気になる…

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?