这是来自UIImageView+AFNetworking
库。AFNetworking使用URL设置UITableViewCell的imageView图像,设置图像后imageview框仍为0
AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest];
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
if ([[urlRequest URL] isEqual:[[self.af_imageRequestOperation request] URL]]) {
if (success) {
success(operation.request, operation.response, responseObject);
} else {
self.image = responseObject;
[self setNeedsLayout];
[self setNeedsDisplay];
}
self.af_imageRequestOperation = nil;
}
我setNeedsLayout
和setNeedsDisplay
增加。在这种情况下,imageview(UITableViewCell
的imageView)仍具有0,0,0,0
框架。单击单元格将刷新imageview,否则图像不显示。
如何强制调整UIImageView
的大小?
我试图把在
self.image = responseObject;
self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y,
self.image.size.width, self.image.size.height);
[self setNeedsDisplay];
[self setNeedsLayout];
基于设置框的
How to make UIImageView automatically resize to the size of the image loaded
的溶液。我可以在那里注销一个更大的框架,但它不会显示在屏幕上。