Is there a way to detect running animations in iOS?

I am trying to find a way to determine if a view is animating.

Example: I applied a shadow on a view layer, specifying shadowPath for performance. When the image size changes, the shadow should be animated. I can observe the view frame and change the shadowPath of the layer accordingly. But when resizing the view, the shadow jumps forward because the change is not animated.

I know how to animate shadowPath with CABasicAnimation, but I need to know the properties of the current animation so that I can apply them to my animation (mainly: duration, easing).

This is a component of the structure, so I just cannot assume that I know the properties of duration and attenuation in advance.

Is there a way to detect start / run animations when watching a frame?

+6
source share
2 answers

You can get all the animations attached to a certain layer of the view, knowing its key, calling

[yourView.layer animationForKey:@"key"] 

to get all keys for which there is animation, call

 NSArray* keys = [yourView.layer animationKeys]; 
+12
source

I think the best practice should be ...

 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]; 
0
source

Source: https://habr.com/ru/post/906000/


All Articles