1

我正在尝试通过在视图加载后来回更改 alpha 级别来使其中包含图像的 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
                 }];

它会导致 alpha 首先动画到 0.0,然后回到原来的 (1.0),然后一遍又一遍地做这两件事......

于 2012-07-12T06:20:31.690 回答