使uibutton脉动.

Hur*_*rkS 1 iphone uibutton uiviewanimation ios

我试图通过在视图加载后来回改变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++;
    }

}
Run Code Online (Sandbox Code Playgroud)

从viewdidload方法调用此方法,

我知道但是我最好的尝试,如果你对如何实现这一点有任何想法,我将不胜感激.

Baz*_*nga 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];
Run Code Online (Sandbox Code Playgroud)

你可以尝试一下.


Dav*_*ist 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
                 }];
Run Code Online (Sandbox Code Playgroud)

它将导致alpha首先动画为0.0,然后回到原始(1.0),然后反复做两件事......