测试 UIView 是否处于动画中间 [英] Test whether a UIView is in the middle of animation
问题描述
有什么方法可以判断 UIView 是否在动画中间?当我在移动时打印出视图对象时,我注意到有一个动画"条目:
Is there any way to tell if a UIView is in the middle of an animation? When I print out the view object while it is moving I notice that there is an "animations" entry:
search bar should end editing: <UISearchBar: 0x2e6240; frame = (0 0; 320 88); text = ''; autoresize = W+BM; animations = { position=<CABasicAnimation: 0x6a69c40>; bounds=<CABasicAnimation: 0x6a6d4d0>; }; layer = <CALayer: 0x2e6e00>>
当动画停止并打印视图时,动画"条目现在消失了:
When the animation has stopped and I print the view, the "animations" entry is now gone:
search bar should end editing: <UISearchBar: 0x2e6240; frame = (0 0; 320 88); text = ''; autoresize = W+BM; layer = <CALayer: 0x2e6e00>>
推荐答案
A UIView
有一个层 (CALayer
).您可以发送 animationKeys
到它,它将为您提供一组键,用于标识附加到图层的动画.我想如果有任何条目,则动画正在运行.如果您想更深入地挖掘,请查看 CAMediaTiming
协议.它提供有关当前动画的更多信息.
A UIView
has a layer (CALayer
). You can send animationKeys
to it, which will give you an array of keys which identify the animations attached to the layer. I suppose that if there are any entries, the animation(s) are running. If you want to dig even deeper have a look at the CAMediaTiming
protocol which CALayer
adopts. It does some more information on the current animation.
重要:如果您使用nil
键([layer addAnimation:animation forKey:nil]
)添加动画,animationKeys
返回 nil
.
Important: If you add an animation with a nil
key ([layer addAnimation:animation forKey:nil]
), animationKeys
returns nil
.
这篇关于测试 UIView 是否处于动画中间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!