iOS SDWebImage fade in new image

后端 未结 8 1486
北海茫月
北海茫月 2021-01-31 06:36

I\'ve been using SDWebImage on my iPhone app to handle all of the image loading. I am using a placeholder image, and I want to crossfade or fade in the new image once it loads.

8条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-31 06:57

    SWIFT:

    func setSDWebImageWithAnimation(imageViewToSet mImageView:UIImageView, URLToSet imageURL:NSURL!)
        {
            mImageView.image = UIImage(named: "favouritePlaceholder")
            SDWebImageManager.sharedManager().downloadImageWithURL(imageURL, options: nil, progress: nil) { (downloadedImage:UIImage!, error:NSError!, cacheType:SDImageCacheType, isDownloaded:Bool, withURL:NSURL!) -> Void in
                mImageView.alpha = 0
                UIView.transitionWithView(mImageView, duration: 1.0, options: UIViewAnimationOptions.TransitionCrossDissolve, animations: { () -> Void in
                    mImageView.image = downloadedImage
                    mImageView.alpha = 1
                    }, completion: nil)
    
            }
        }
    

提交回复
热议问题