【发布时间】:2014-11-09 14:31:31
【问题描述】:
我正在使用setImageWithURLRequest 方法将图像异步下载到自定义的 UIImageViews 并在下载图像时放置一个占位符。问题是这个类别以某种方式将下载的图像放在我自定义的 UIImageView 的顶部。使用视图层次调试器无法调试问题,因为这些额外的不需要的图像根本不会出现在那里。这是我用于请求的代码:
ExhibitImageView *newExhibitImageView = [[ExhibitImageView alloc] initWithFrame:_pictureScrollView.bounds];
NSURL *url = [NSURL URLWithString:@"http://uddddpload.wikimedia.org/wikipedia/commons/thumb/e/ec/Karl_Brullov_-_The_Last_Day_of_Pompeii_-_Google_Art_Project.jpg/1280px-Karl_Brullov_-_The_Last_Day_of_Pompeii_-_Google_Art_Project.jpg"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
UIImage *placeholderImage = [UIImage imageNamed:@"placeholderImage"];
__weak ExhibitImageView *weakExhibitImageView = newExhibitImageView;
[newExhibitImageView setImageWithURLRequest:request placeholderImage:placeholderImage success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
weakExhibitImageView.image = image;
[weakExhibitImageView setNeedsLayout];
[weakExhibitImageView setContentMode:UIViewContentModeScaleAspectFill];
} failure:nil];
然后我使用一些代码将这个自定义视图放到滚动视图中(这可能与问题有关):
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGRect frame = CGRectMake(0, 0, screenWidth, screenRect.size.height);
CGFloat totalWidth = page * screenWidth;
frame.origin.x = totalWidth;
newExhibitImageView.frame = frame;
[_pictureScrollView addSubview:newExhibitImageView];
这是我在申请中得到的:
这就是它在 View Hierarchy 调试器 (Xcode) 中的外观 - 完全正确,它必须是这样的:
有解决此问题的方法吗?
【问题讨论】:
标签: ios objective-c uiimageview afnetworking objective-c-blocks