は、success
ブロックを提供するsetImageWithURL
のレンディションと組み合わせて使用できます。
[imageView setImageWithURL:[NSURL URLWithString:@"http://i.imgur.com/r4uwx.jpg"]
placeholderImage:[UIImage imageNamed:@"placeholder-avatar"]
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
[UIView transitionWithView:self.imageView
duration:0.3
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.imageView.image = image;
}
completion:NULL];
}
failure:NULL];
更新:ところで
、あなたがあれば、あなたがイメージが空白でないプレースホルダ場合、あなたはおそらく交差transitionWithView
を経由して溶解するのでしょう
[imageView setImageWithURL:[NSURL URLWithString:@"http://i.imgur.com/r4uwx.jpg"]
placeholderImage:[UIImage imageNamed:@"placeholder-avatar"]
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
self.imageView.alpha = 0.0;
self.imageView.image = image;
[UIView animateWithDuration:0.25
animations:^{
self.imageView.alpha = 1.0;
}];
}
failure:NULL];
あるいは、ダウンロードが完了するまで、画像ビュー(およびself
、ビューまたはビューコントローラも参照してください)が保持されていることを心配しています。
__weak UIImageView *weakImageView = self.imageView;
[imageView setImageWithURL:[NSURL URLWithString:@"http://i.imgur.com/r4uwx.jpg"]
placeholderImage:[UIImage imageNamed:@"placeholder-avatar"]
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
UIImageView *strongImageView = weakImageView; // make local strong reference to protect against race conditions
if (!strongImageView) return;
[UIView transitionWithView:strongImageView
duration:0.3
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
strongImageView.image = image;
}
completion:NULL];
}
failure:NULL];
あなたは、ダウンロードが完了するまで画像表示が保持されているので、あなたはまた、任意のビューコントローラのdealloc
方法で進行中のダウンロードをキャンセルする可能性があることを行う場合でも:
- (void)dealloc
{
// if MRC, call [super dealloc], too
[_imageView cancelImageRequestOperation];
}
出典
2013-07-18 17:26:58
Rob
ただし、保持サイクルには注意してください。 –
@MarceloFabriあなたは精巧にできますか?どちらがサイクルを保持する? – timpone
ロブ、ローディングのためにフェードエフェクトを作ることが可能かどうか知っていますか?つまり、0%読み込み=不透明度0.0、100%読み込み - 不透明度1.0 –