Is there a way to detect a running animation in iOS?

I'm trying to find a way to detect if a view is being animated.

Case in point: I have applied a shadow on the layer of a view, specifying a shadowPath for performance. When the view is resized, the shadow should animate along. I can observe the frame of the view, and change the shadowPath of the layer accordingly. But while the view is resizing, the shadow jumps ahead since the change is not animated.

I know how to animate the shadowPath using a CABasicAnimation, but I need to know the properties of an ongoing animation so that I can apply them to my animation as well (mostly: duration, easing).

This is in a framework-type component, so I just cannot assume I know the duration and easing properties on beforehand.

Is there a way to detect a starting/running animation when observing the frame?


You can retrieve all animations attached to particular view's layer knowing it's key by calling

[yourView.layer animationForKey:@"key"]

to get all keys there is some animation for, call

NSArray* keys = [yourView.layer animationKeys];

我认为最好的做法应该是......

UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.7];
[UIView setAnimationBeginsFromCurrentState:YES];

.....your code
// Set animation did stop selector before committing the animations

[UIView setAnimationDidStopSelector:@selector(animationFinished:)];

[UIView commitAnimations];
链接地址: http://www.djcxy.com/p/74182.html

上一篇: CABasicAnimation与“frameOrigin”的keyPath一起使用是否安全?

下一篇: 有没有办法在iOS中检测正在运行的动画?