ios - UILabel 闪烁效果

标签 ios objective-c iphone xcode6

我正在使用具有闪烁效果的 UIButton。我已将此代码用于 UIButton 的闪烁效果

UIButton *random = (UIButton *)[self.view viewWithTag:i+20];
random.alpha = 0;
[UIView animateWithDuration:0.2 delay:0.2 options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse animations:^{
         random.alpha = 1;
        } completion:nil];

此代码将使 UIButton 闪烁,但我想在闪烁 3 次后停止这种闪烁效果 我不知道如何停止这种闪烁效果。 因此,如果有人知道解决方案,请帮助我。 提前致谢。

最佳答案

使用 CABasicAnimation 代替 UIView 动画

UIButton *random = (UIButton *)[self.view viewWithTag:i+20];
random.alpha = 0;

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
[animation setFromValue:[NSNumber numberWithFloat:0.0]];
[animation setToValue:[NSNumber numberWithFloat:1.0]];
[animation setDuration:0.2f];
[animation setRepeatCount:3];
[animation setAutoreverses:YES];
[animation setRemovedOnCompletion:NO];
[random.layer addAnimation:animation forKey:@"animation"];

关于ios - UILabel 闪烁效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30391899/

相关文章:

iOS Calc X 位置以将元素放置在 View 上

iphone - 启用 allowMultipleSelection 时,如何在 UICollectionView 中以编程方式取消选择单元格?

iphone - Storyboard ViewController 中的多态性

ios - 检测屏幕上任意位置的触摸

ios - 要求用户在注册过程后允许推送通知

AppStore 中的 iOS 应用程序在更新到 iOS 8.0.2 后崩溃但仍在设备和模拟器上运行

ios - 将 gif 添加到 UIImageView

objective-c - Navigation Bar延迟更新barTintColor iOS 10

ios - 原生 iOS 国家/地区选择器

ios4 - 当我在 iPhone 中按住 UIButton 2 秒时触发操作