测试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>>
推荐答案
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.
这篇关于测试UIView是否在动画中间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!