ios圆角优化-不掉帧

因网络图片加载用的是SDWebImage所以下面以sd加载图片为例

//普通的加载网络图片方式(已不能满足需求,需要改进)
[self sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:placeholderImage]];

//设置圆角图片的加载方法
[self sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:placeholderImage] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            if (!error) {
                //图片需要手动缓存处理成圆角的图片(该方法用的是YYImage里面的处理方式)
                UIImage *radiusImage = [image imageByRoundCornerRadius:image.size.width * (radius / self.size.width) corners:corners borderWidth:borderWidth borderColor:borderColor borderLineJoin:borderLineJoin];
                self.image = radiusImage;
                //将带圆角的图片缓存下来
                [[SDImageCache sharedImageCache] storeImage:radiusImage forKey:cacheUrlStr completion:nil];
                //清除原有非圆角图片缓存
                [[SDImageCache sharedImageCache] removeImageForKey:url.absoluteString withCompletion:nil];
            }
}];

到此为止就已经结束了

demo下载地址

by:初光夫

posted @ 2018-12-12 15:15  WidgetBox  阅读(408)  评论(0编辑  收藏  举报