1

次のパラメーターを使用して、さまざまな時間を使用して UIImageView のフェードインとフェードアウトを行いたいと思います。

  • t = 0 ... UIImageView のアルファ = 0
  • t = 0.5s ... UIImageViewのアルファ = 0.7
  • t = 0.7s ... UIImageViewのアルファ = 0

これはCAAnimationまたは他の方法で行うことができますか? どうすればそれができますか?

助けてくれてありがとう!

4

3 に答える 3

6
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];
}

それが役に立てば幸い

于 2011-07-04T06:49:13.673 に答える
3

おそらくCAKeyframeAnimationを調べる必要があります。複数の時点の値を設定できます。

于 2010-02-17T23:23:39.457 に答える
2

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];
}
于 2010-02-17T23:56:27.497 に答える