iphone - 让 uibutton 跳动。

标签 iphone ios uibutton uiviewanimation

我正在尝试通过在 View 加载后来回更改 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 方法中调用的,

我知道这很粗糙,但这是我最好的尝试,如果您对我如何实现这一目标有任何想法,将不胜感激。

最佳答案

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

你可以尝试一下。

关于iphone - 让 uibutton 跳动。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11445298/

相关文章:

iphone - 使用 AVPlayer 在 iPhone 上播放许多不同的视频

iphone - UISearchBar 不显示范围栏

ios - 为什么这个 UIAlertView 的位置没有改变?

html - CSS 未在 IOS < ver 10 设备上加载

iphone - 为什么这个 UIButton 在禁用时仍然触发事件处理程序

iphone - 如何防止 iPhone 自动旋转

iOS 设置(隐私 -> 定位服务 -> 选择我的应用 -> 更改允许访问)崩溃

ios - Swift 属性观察不会覆盖

ios - Xcode 6按钮目标不起作用

ios - 带有按钮 addTarget 事件的标签不会触发