iOS CATransition动画实现SDWebImage图片下载完成渐变动画

原文地址

http://www.jianshu.com/p/f0b3db7edc93

代码实现

在图片下载完成的block中给image.layer添加转场动画

- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
     __weak typeof(self) weakSelf = self;
    [self sd_setImageWithURL:url placeholderImage:placeholder completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {

        if (image && cacheType == SDImageCacheTypeNone) {
            CATransition *transition = [CATransition animation];
            transition.type = kCATransitionFade;
            transition.duration = 0.3;
            transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
            [weakSelf.layer addAnimation:transition forKey:nil];
        }

    }];

}

你可能感兴趣的:(iOS高级进阶)