不使用對的UIImageView AFNetworking的分類方法時,此工作,但我意識到AF可能是覆蓋不管,因爲這樣做是發生異步:設置UIImageView的圓潤與AFNetworking setImageWithURL角落:
這是我自定義的UITableViewCell(自己是單元格):
NSURL *url = [NSURL URLWithString:video.thumbnail];
[self.imageView setImageWithURL:url
placeholderImage:[UIImage imageNamed:@"Logo.png"]];
// not working
CALayer *layer = [self.imageView layer];
[layer setMasksToBounds:YES];
[layer setCornerRadius:10.0];
嘗試將它放在調用setImageWithURL之前。
這是我現在並沒有四捨五入的角落:
NSURL *url = [NSURL URLWithString:_video.thumbnail];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
UIImage *placeHolder = [UIImage imageNamed:@"Logo"];
__weak UIImageView *imageView = self.thumbnail;
[self.thumbnail setImageWithURLRequest:request placeholderImage:placeHolder success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
imageView.image = image;
// round the edges of the video thumbnail
CALayer *layer = [imageView layer];
[layer setMasksToBounds:YES];
[layer setCornerRadius:8.0];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
NSLog(@"couldn't load image: %@", [error localizedDescription]);
}];
當你從一個url下載圖片時,需要一些時間取決於互聯網的速度,在這種情況下,imageView沒有正確加載來自url的圖片。您應該使用阻止或異步來首先完全下載圖像,然後從中提取圖層。 – MrWaqasAhmed