【发布时间】:2018-08-09 11:08:46
【问题描述】:
我在 UITableView 中使用 SDWebImage。 我需要根据图像框架创建单元格大小,我正在使用这种方法:
-(UIImage *)imageManager:(SDWebImageManager *)imageManager transformDownloadedImage:(UIImage *)image withURL:(NSURL *)imageURL{
CGSize newSize = CGSizeMake(self.cmImage.frame.size.width, self.cmImage.frame.size.width * image.size.height / image.size.width);
// Create a graphics image context
UIGraphicsBeginImageContext(newSize);
// draw in new context, with the new size
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
// Get the new image from the context
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
// End the context
UIGraphicsEndImageContext();
return newImage;
}
我打电话给这个
- (void)awakeFromNib {
SDWebImageManager.sharedManager.delegate = self;
}
在 cellForRowAtIndexPath 我这样做了:
[SDWebImageManager.sharedManager downloadImageWithURL:[NSURL URLWithString:_model.data] options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
self.cmImage.image = image;
}];
在单元格中调整图像大小并更改cmImage的框架
但我认为此方法对于创建 cmImage 框架的响应为时已晚,并且在我滚动 tableView 后某些图像正在调整大小,并且对于某些单元格我加载了不同的图像
我还收到警告 [UIView frame] must be used only from main thread 从这一行:
CGSize newSize = CGSizeMake(self.cmImage.frame.size.width, self.cmImage.frame.size.width * image.size.height / image.size.width);
我到底做错了什么?
【问题讨论】:
标签: objective-c uitableview sdwebimage