版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_18683985/article/details/89333834
就拿UIView块动画做例子吧.
加入我们拿一个UIView做动画.
UIView *redView = [UIView new];
UIView animationWithDuration:.xx animation:^{
xxxx
} complete:^{
// 完成代码块
}];
当然.我们可以弄一个__block的属性.利用这个完成回调去记录一下动画状态.
但是拓展到其他的动画比如CABaseAnimation啊.keyxxxx之类的啊.就不太方便.
首先.UIView动画等动画.本质是对CALayer做动画.我们在UIView停止一个块动画文章中提到了.要停止一个动画(看完这篇文章就能这样拓展了)我们可以让这个layer removeAllanimation.那么.我们的动画肯定是加到了layer上.
然后翻一下CALayer的头文件我们可以看到这个属性.
/* Returns an array containing the keys of all animations currently
* attached to the receiver. The order of the array matches the order
* in which animations will be applied. */
/// 包含当前所有动画的键的数组
- (nullable NSArray<NSString *> *)animationKeys;
那么我们只需要查看一下animationKeys的count是否为空.为空就为无动画.不为空就是有动画.
一次动画看起来没啥毛病
多次调用块动画看起来就不太对了.这是因为,complete是记录的当前块动画结束.而不是动画View上没有动画了的属性.所以我们判断一个View没动画可以判断他layer上的animationKeys的数目是否为0