2
我想動畫多個UIImageViews.Image上的圖像來自服務器端與Url,所以我請求URL並將其轉換爲圖像,我給動畫uiimageview即crossdissolve,出現一個問題圖像參考在UIImageView中更改意味着第一它顯示不同的圖像,當我滾動然後其他圖像顯示在相同的UIImageView.This問題將發生只有第一次,因爲我保持imagecache.Any有關這個bahavious的想法?以下是我使用的代碼。爲UIImageView提供動畫時,爲什麼UIImage引用會改變?
-(void)requestForImage:(NSString*)strURL{
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
NSURLRequest *request;
NSString * newImageURL = [strURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
request = [NSURLRequest requestWithURL:[NSURL URLWithString:newImageURL]];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
UIImage *image = [UIImage imageWithData:data];
if ([data length] > 0 && error == nil && image) //If success
{
//receive data
[[myImage sharedMyclass] setImage:image withKey:strURL];
dispatch_queue_t queue_ = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue_, ^{
UIImage *image = [[myImage sharedMyclass] imageForURL:strURL]; //That return image from particular path
[self performSelectorOnMainThread:@selector(receivedImage:) withObject:image waitUntilDone:NO];
[data writeToFile:[[NSUserDefaults standardUserDefaults] valueForKey:strURL] atomically:YES];
dispatch_sync(dispatch_get_main_queue(), ^{
[UIView transitionWithView:self
duration:2.0
options: UIViewAnimationOptionTransitionCrossDissolve|UIViewAnimationOptionAllowUserInteraction
animations:^{
self.image = image;
}
completion:NULL];
self.contentMode = UIViewContentModeScaleAspectFit;
});
});
}
}];
}