Suk*_*rob 8 objective-c ios5 sdwebimage
如何在缓存之前调整来自URL的图像的大小,缩放和裁剪.我尝试使用以下代码实现此目的.
[cell.profilePicture setImageWithURL:[NSURL URLWithString:[rowData objectForKey:@"pictureUrl"]] placeholderImage:nil];
cell.profilePicture.image = [self imageByScalingAndCroppingForSize:CGSizeMake(cell.profilePicture.frame.size.width, cell.profilePicture.frame.size.height) image:cell.profilePicture.image];
Run Code Online (Sandbox Code Playgroud)
这产生了一个奇怪的结果.首先,它显示未调整大小/缩放/裁剪的版本.但是,当我向下滚动然后返回时,它会显示调整大小/缩放/裁剪的版本.我知道这段代码首先缓存图像并调整大小/缩放/裁剪它们.但是,我无法想出更好的解决方案.我认为应该有一些能够下载图像的东西,以便独立调整大小/缩放/裁剪和缓存.有任何想法吗?
谢谢.
Suk*_*rob 13
我自己想出了解决方案.
代替
[cell.profilePicture setImageWithURL:[NSURL URLWithString:[rowData objectForKey:@"pictureUrl"]] placeholderImage:nil];
Run Code Online (Sandbox Code Playgroud)
自动下载和缓存图像,使用它
SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadWithURL:url delegate:self options:0 success:^(UIImage *image)
{
cell.profilePicture.image = [self imageByScalingAndCroppingForSize:CGSizeMake(cell.profilePicture.frame.size.width, cell.profilePicture.frame.size.height) image:image];
} failure:nil];
Run Code Online (Sandbox Code Playgroud)
别忘了包括
#import <SDWebImage/UIImageView+WebCache.h>
@interface YourViewController : UIViewController <SDWebImageManagerDelegate>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15066 次 |
| 最近记录: |