闪烁对UILabel的影响
我有一个背景颜色为灰色的UILabel。
我希望在这个标签上闪烁的效果,就像它变得有点白,然后变成灰色,它应该保持发生,直到我以编程方式关闭它。
任何线索如何实现这一目标?
  使用NSTimer 
NSTimer *timer = [NSTimer 
                      scheduledTimerWithTimeInterval:(NSTimeInterval)(1.0)
                            target:self 
                             selector:@selector(blink) 
                             userInfo:nil 
                             repeats:TRUE];
BOOL blinkStatus = NO;
在你的眨眼功能
-(void)blink{
   if(blinkStatus == NO){
      yourLabel.backgroundColor = [UIColor whiteColor];
     blinkStatus = YES;
   }else {
      yourLabel.backgroundColor = [UIColor grayColor];
      blinkStatus = NO;
   }
}
您可以在一个块内完成此操作:
self.yourLabel.alpha = 1;
[UIView animateWithDuration:1.5 delay:0.5 options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse animations:^{
        self.yourLabel.alpha = 0;
} completion:nil];
所以你不需要第二种方法。
斯威夫特3
extension UILabel {
    func startBlink() {
        UIView.animate(withDuration: 0.8,
              delay:0.0,
              options:[.allowUserInteraction, .curveEaseInOut, .autoreverse, .repeat],
              animations: { self.alpha = 0 }, 
              completion: nil)
    }
    func stopBlink() {
        layer.removeAllAnimations()
        alpha = 1
    }
}
