How to disable delegate in UIView setAnimationDelegate: call?

I get crash reports that appear from a UIView animation, invoking a delegate that has been canceled.

Thread 0 Crashed: 0 libobjc.A.dylib 0x334776f6 objc_msgSend + 18 1 UIKit 0x31c566c4 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] 2 UIKit 0x31c565d2 -[UIViewAnimationState animationDidStop:finished:] 3 QuartzCore 0x30045a26 run_animation_callbacks 

I set the current view controller as a delegate for animations using the following template:

 [UIView beginAnimations:nil context:NULL]; [UIView setAnimationBeginsFromCurrentState:YES]; [UIView setAnimationDuration:0.5]; [UIView setAnimationDelegate:self]; ... [UIView commitAnimations]; 

My question is how to set this delegate link to nil in my dealloc method? Is there a way to keep the link to the animation? Or get animation in progress?

+2
source share
1 answer

The CALayer class handles all animations for UIViews. You can access the UIView layer using the layer property. If you replaced the first argument [UIView beginAnimations: context:] with the actual string, you could directly access this animation using the CALayer animationForKey: and removeAnimationForKey: .

In this case, however, it may be sufficient to call [view.layer removeAllAnimations] before the dealloc calls [super dealloc] . This will stop any custom UIView animations and, obviously, remove them from their layer.

+3
source

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


All Articles