5
3

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.

UICollectionViewCellのFade Inアニメーションを作る

Last updated at Posted at 2020-04-03

この記事について

UICollectionViewCellのFade Inアニメーションの作り方

How To

UICollectionViewのdelegateの willDisplay メソッドでalphaをアニメーションする。

注意: デフォルトではアニメーション中はuserControllがdisableされるので、optionsに .allowUserInteraction を設定する。これにより、アニメーション中にもスクロールできる。

    override func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
        cell.alpha = 0
        UIView.animate(withDuration: 0.5, delay: 0.0, options: .allowUserInteraction, animations: {
            cell.alpha = 1
        }, completion: nil)
    }

Result

2020-04-03-1.gif

*輪郭の形が変わって見えるのはgifデータの問題です

5
3
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
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?