Search code examples
iosswiftanimationsdwebimage

Making SDWebImage appear with fade in animation


I would like to set an animation, when an image is loaded.

I use SDWebImage to load pictures:

if let photoUrlString = post?.photoUrl {
         let photoUrl = URL(string: photoUrlString)
         picImg.sd_setImage(with: photoUrl)
}

How can I code a "fade in" effect when the picture is loaded?


Solution

  • Edit: SDWebImage provides seven transitions that execute only when the image is first downloaded (source). These transitions use CATransition.

    guard let photoUrlString = post?.photoUrl else {
        return
    }
    
    let photoUrl = URL(string: photoUrlString)
    
    picImg.sd_imageTransition = .fade
    picImg.sd_setImage(with: photoUrl)