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
viewis not retained anywhere except by its superview, calling[view removeFromSuperView];is completely alright. And, as you’ve afraid,viewwill be released at that time. So, accessing it after theremoveFromSuperViewmethod call will not be safe.You should be retaining
viewinorder to acces it even after you remove it from its superview.Changes in your code:
You have to remove the
viewafter the animation is over. Add the following lines while you create animation.The onAnimationStopped method,