2015-05-22 119 views
0

我正在使用具有闪烁效果的UIButton。我已经使用这个代码上的UIButtonUILabel闪烁效果

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个闪烁,我不知道如何停止该闪烁的效果。 所以,如果有人知道解决方案,请帮助我。 在此先感谢。

回答

1

您可以在动画块中调用[UIView setAnimationRepeatCount:3]。您不应使用UIViewAnimationOptionRepeat标志,因为它会使repeatCount不确定。

我想如果苹果公司没有提供repeatCountUIView动画,因为他们提供了CABasicAnimation,这将是一大倒退。

+0

不工作? –

6

使用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"]; 
+0

哇,这对我很好,谢谢。 –

+0

非常欢迎@PradumnaPatil – abhishekkharwar