Home  >  Q&A  >  body text

ios - 如何判断CALayer正在做动画?

场景:存在一个UILabel实例,对它做缩放,如何清除知道他正在缩放?

伊谢尔伦伊谢尔伦2716 days ago361

reply all(3)I'll reply

  • 迷茫

    迷茫2017-04-18 09:33:36

    There is no relevant API that can determine whether animation is being executed. There is only the following method, which can be determined by judging isAnimating

    // 设置初始值(最好使用全局或者属性)
        __block BOOL isAnimating =YES;
        self.transform = CGAffineTransformMakeScale(6, 6);
        [UIView animateKeyframesWithDuration:0.333 delay:0 options:0 animations:^{
            
            
            self.transform = CGAffineTransformMakeScale(1, 1);
        } completion:^(BOOL finished) {
            // 成功回调改为NO
            isAnimating = NO;
            completion();
        }];

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 09:33:36

    -(BOOL)isAnimated
    {
        BOOL animated = self.layer.animationKeys.count > 0;
        
        for (UIView *subView in self.subviews) {
            
            animated |= subView.isAnimated;
        }
        
        return animated;
        
    }

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:33:36

    Personally, it’s best to record using the bool attribute of label

    reply
    0
  • Cancelreply