1

ビューが読み込まれたらアルファレベルを前後に変更して、画像が含まれているuibuttonをゆっくりと脈動させようとしています...

現在私はこれを行っていますが、何もしません...。

-(void)loopdyloop
{
    while ( myCount < 1000 )
    {

        [UIView animateWithDuration:3.0
                              delay:0.0f
                            options:UIViewAnimationCurveEaseOut
                         animations:^{


                             iconButton.alpha = 0.0;


                         } completion:^(BOOL finished) {
                             if (finished) {

                                 NSLog(@"animated");
                             }
                         }];


        [UIView animateWithDuration:3.0
                              delay:0.0f
                            options:UIViewAnimationCurveEaseOut
                         animations:^{


                             iconButton.alpha = 1.0;


                         } completion:^(BOOL finished) {
                             if (finished) {

                                 NSLog(@"animated");
                             }
                         }];




        myCount++;
    }

}

このメソッドは、viewdidloadメソッドから呼び出されます。

私はかなり粗雑ですが、それは私の最善の試みです。私がこれをどのように達成できるかについて何か考えがあれば、それは大いにありがたいです。

4

2 に答える 2

14

のボタンレイヤーにこれを適用するのはどうですかviewDidLoad:

CABasicAnimation *pulseAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
pulseAnimation.duration = .5;
pulseAnimation.toValue = [NSNumber numberWithFloat:1.1];
pulseAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
pulseAnimation.autoreverses = YES;
pulseAnimation.repeatCount = FLT_MAX;
[YOURButton.layer addAnimation:pulseAnimation forKey:nil];

そして、あなたはそれを試すことができます。

于 2012-07-12T08:44:20.763 に答える
5

永久に繰り返したい場合は、次のように、自動反転して繰り返すアニメーションオプションを追加できます。

[UIView animateWithDuration:3.0
                      delay:0.0f
                    options:UIViewAnimationCurveEaseOut | 
                            UIViewAnimationOptionRepeat | 
                            UIViewAnimationOptionAutoreverse
                 animations:^{
                     iconButton.alpha = 0.0;
                 } 
                 completion:^(BOOL finished) {
                     // You could do something here
                 }];

これにより、アルファは最初に0.0にアニメーション化され、次に元の(1.0)に戻り、これら2つのことを何度も繰り返します...

于 2012-07-12T06:20:31.690 に答える