我正在使用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)中的外观 - 完全正确以及它必须如何:
有关如何解决此问题的任何想法?
答案 0 :(得分:0)
在自定义视图上设置clipsToBounds = YES;
属性解决了这个问题。似乎AFNetworking只是覆盖默认值。唯一的问题出现了 - 为什么我无法使用View Hierarchy Debugger看到这个问题?