开发者

Animations make my app crash: How can I remove them?

开发者 https://www.devze.com 2022-12-24 10:56 出处:网络
In my app, I create view controller objects as I need them. When a view controller goes away, I get rid of it by calling -removeFromSuperview on it\'s view and then set the retaining property to nil.

In my app, I create view controller objects as I need them. When a view controller goes away, I get rid of it by calling -removeFromSuperview on it's view and then set the retaining property to nil.

That way my app uses very low memory all the time. But there's a problem: I have heavy animations going on in some view controllers, and every animation always has an animation delegate which is self. Now the thing that happens is: When there are animations running and I drop the view control开发者_开发知识库ler, it goes away - and at some point when one of those animations finishes it seems to crash.

So the question is: How to remove any running animation from a view and all it's subviews?


Agreed. There may be some confusion on how you add/remove the subview, and how you retain/release it. Make sure that you are following these guidelines:

// To add
AView * aSubView = [[AView alloc] init];
[aContainerView addSubview:aSubView];
[aSubView release]; // aSubView is retained by aContainerView

... and later on

// To remove
[aSubView removeFromSuperview]; // and nothing else!

Do not do this:

[self removeFromSuperview]; // Don't cut the branch on which you are sitting

(you already knew that!)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号