2012-07-12 55 views
1

我试图在它通过改变α水平来回一次的观点负载跳动缓慢,以至于有一个图像的UIButton ...使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方法调用,

相当粗糙,但我知道它我最好的尝试,如果你对我怎么能做到这一点,将不胜感激的任何想法。

回答

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

和你可以试用它。

+0

我实际上看到了类似这个代码的东西..但我无法弄清楚如何将它应用到一个uibutton。我认为会有更多的东西不仅仅是mybutton.layer:P:P感谢你的高举!动画真棒! :P – HurkNburkS 2012-07-12 20:30:05

+0

哈哈哈,我也是。我想你只需要在你的按钮层应用它。所以goodluck :) – Bazinga 2012-07-13 00:29:27

+0

这看起来不错! – pob21 2012-09-24 18:56:59

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),然后做这两件事情一遍又一遍又一遍......