【问题标题】:UIImage+AFNetworking puts another image on top of loaded imageUIImage+AFNetworking 将另一个图像放在加载的图像之上
【发布时间】: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


    【解决方案1】:

    在自定义视图上设置clipsToBounds = YES; 属性解决了这个问题。似乎 AFNetworking 只是覆盖了默认值。唯一的问题出现了 - 为什么我无法使用 View Hierarchy Debugger 看到这个问题?

    【讨论】:

    • AFNetworking 不会覆盖任何内容。 clipsToBounds 默认为 false。
    • 在我用同一张图片实现 AFNetworking 之前,它已经工作了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-17
    • 1970-01-01
    相关资源
    最近更新 更多