开发者

beginAnimations commitAnimations retain a view?

开发者 https://www.devze.com 2023-04-11 08:31 出处:网络
Suppose,(pseudo code开发者_高级运维) view.alpha = 1.0; [beginAnimmations] [animationDuration = 1.0]

Suppose,(pseudo code开发者_高级运维)

view.alpha = 1.0;  
[beginAnimmations]  
[animationDuration = 1.0]
view.alpha = 0.0;
[commitAnimations]

[view removeFromSuperView];

When view is not retained anywhere else than its superview, hence [view removeFromSuperView] will make the view be dealloc-ed.

Is this safe? or How can I do this correctly?


If the view is not retained anywhere except by its superview, calling [view removeFromSuperView]; is completely alright. And, as you've afraid, view will be released at that time. So, accessing it after the removeFromSuperView method call will not be safe.

You should be retaining view inorder to acces it even after you remove it from its superview.

Changes in your code:

You have to remove the view after the animation is over. Add the following lines while you create animation.

[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(onAnimationStopped)];

The onAnimationStopped method,

- (void)onAnimationStopped {

    [view removeFromSuperview];
}
0

精彩评论

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