別の画像で UIImageView の画像を設定しようとしています。[imageView setImage: image] を実行できることはわかっています。しかし、画像を変更する際にディゾルブ効果(アニメーション)を追加することはできますか?
1094 次
3 に答える
3
私は以前にこれを行いましたが、これがあなたを助けるコードです.このコードは、あなたが上で説明した問題に対してうまく機能します.
-(void)changeImage
{
myImageView.animationImages=[NSArray arrayWithArray:self.yourImageArray];
myImageView.animationDuration=10.0;
myImageView.animationRepeatCount=0;
[myImageView startAnimating];
myImageView.transform = CGAffineTransformMakeRotation(M_PI/2);
[self.view addSubview:myImageView];
//The timers time interval is the imageViews animation duration devided by the number of images in the animationImages array. 20/5 = 4
NSTimer *timer = [NSTimer timerWithTimeInterval:2.0
target:self
selector:@selector(onTimer)
userInfo:nil
repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
[timer fire];
}
//これにより、画像がフェードインおよびフェードアウトします。
-(void)onTimer{
[UIView animateWithDuration:2.0 animations:^{
myImageView.alpha = 0.0;
}];
[UIView animateWithDuration:0.5 animations:^{
myImageView.alpha = 1.0;
}];
}
クロス ディゾルブが必要な場合は、この UIViewAnimationOptionTransitionCrossDissolve を使用できます。お気軽にお問い合わせください。
于 2013-11-04T06:14:02.793 に答える
2
これを実現するには、UIView のtransitionWithView
メソッドを使用できます。
サンプル コード スニペット:
UIImage * newImage= [UIImage imageNamed:@"newImg.png"];
[UIView transitionWithView:self.view
duration:3.0f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
yourImageView.image = newImage;
} completion:nil];
于 2013-11-04T06:02:50.080 に答える