我正在使用具有闪烁效果的 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/