如何取消设置代理上的UIView setAnimationDelegate:打电话? [英] How to unset delegate on UIView setAnimationDelegate: call?
问题描述
我收到了,似乎是从一个UIView动画调用已dealloced委托崩溃报告。
I am receiving crash reports that appear to be from a UIView animation calling a delegate that has been dealloced.
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 am setting the current view controller as the delegate for animations using the following pattern:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
...
[UIView commitAnimations];
我的问题是,我该如何设置我的dealloc方法该委托引用零?是否有某种方式保留到动画的参考?或正在进行获取动画?
My question is, how do I set that delegate reference to nil in my dealloc method? Is there some way to retain a reference to an animation? Or fetch animations in progress?
推荐答案
的CALayer的类处理UIViews所有动画。您可以使用层
属性来访问的UIView的层。如果你要替换的第一个参数[UIView的beginAnimations:背景:]
与实际字符串,将有可能直接使用的CALayer的 animationForKey:
和 removeAnimationForKey:
方法
The CALayer class handles all animations for UIViews. You can access the UIView's layer using the layer
property. If you were to replace the first argument of [UIView beginAnimations: context:]
with an actual string, it would be possible to access that animation directly using CALayer's animationForKey:
and removeAnimationForKey:
methods.
在这种情况下,虽然,它可能是足以叫 [view.layer removeAllAnimations]
在的dealloc
调用 [超级的dealloc]
。这将停止任何自定义的UIView动画,很明显,从层中删除。
In this case though, it might be enough to call [view.layer removeAllAnimations]
before dealloc
calls [super dealloc]
. This will stop any custom UIView animations and, obviously, remove them from its layer.
这篇关于如何取消设置代理上的UIView setAnimationDelegate:打电话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!