2
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 5 years have passed since last update.

【SDWebImage】UITableViewCellやUICollectionViewCell内の画像をフェードインで表示する

Posted at

単純に cellForRowAtIndexPath や willDisplayCell 内で画像のフェードイン処理を書いただけではcellが読み込まれるたびにフェードイン処理が走ってしまう。

SDWebImageは表示した画像をキャッシュしてくれるので、
画像を表示する際、キャッシュ以外(ネットワーク)から取得した場合のみフェードインするようにすれば良い。

imageView.sd_setImageWithURL($0, placeholderImage: UIImage(named: "placeholderImage"), options: .CacheMemoryOnly, completed: { (image, error, type, url) in
    if type == .None {
        // キャッシュ以外から画像を取得した場合はフェードインで画像を表示
        self.imageView.alpha = 0
        UIView.animateWithDuration(0.5, animations: {
             self.imageView.alpha = 1
        })
     }
})
2
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
2
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?