次のパラメーターを使用して、さまざまな時間を使用して UIImageView のフェードインとフェードアウトを行いたいと思います。
- t = 0 ... UIImageView のアルファ = 0
- t = 0.5s ... UIImageViewのアルファ = 0.7
- t = 0.7s ... UIImageViewのアルファ = 0
これはCAAnimationまたは他の方法で行うことができますか? どうすればそれができますか?
助けてくれてありがとう!
次のパラメーターを使用して、さまざまな時間を使用して UIImageView のフェードインとフェードアウトを行いたいと思います。
これはCAAnimationまたは他の方法で行うことができますか? どうすればそれができますか?
助けてくれてありがとう!
if (imgDefault.alpha == 0.0) {
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration: 3.0];
[UIView setAnimationDelegate: self];
imgDefault.alpha = 1.0;
[UIView commitAnimations];
}
else {
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration: 3.0];
[UIView setAnimationDelegate: self];
imgDefault.alpha = 0.0;
[UIView commitAnimations];
}
それが役に立てば幸い
おそらくCAKeyframeAnimationを調べる必要があります。複数の時点の値を設定できます。
UIView には、使用できる setAnimationDidStopSelector: メソッドがあります。beginAnimations ブロックを使用してフェードイン アニメーションをセットアップし、didStop セレクターをフェードアウト アニメーション ブロックのみを含む別のメソッドに設定するだけです。これらのアニメーション ブロックはそれぞれ、異なるアニメーション期間を持つことができます。
このようなもの:
[UIView beginAnimations:next context:context];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(fadeOut:finished:context:)];
myView.alpha = 0.7;
[UIView commitAnimations];
-(void)fadeOut:(NSString*)animationID finished:(BOOL)finished context:(void*)context {
[UIView beginAnimations:nil context:context];
[UIView setAnimationDuration:0.2];
myView.alpha = 0.0;
[UIView commitAnimations];
}