开发者

UIView Animation Problem

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.30f];

[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:viewSettings cache:YES];   
viewSettings.alpha = 0;
[viewSettings removeFromSuperview];
[UIView commitAnimations];

I ve written the code above that works well when I add the view via animation, but it doesn't work when i remove th开发者_高级运维e view from superview. Animation works if I remove [viewSettings removeFromSuperview] line. I don't know where I'm doing wrong.


You need to remove it from the superview after the animation has completed. This is very easy to accomplish if you use the blocks based API, which Apple is encouraging you to do:

[UIView transitionWithView:viewSettings 
                  duration:0.30f 
                   options:UIViewAnimationOptionTransitionNone  
                animations:^{ 
    [viewSettings setAlpha:0];
} completion:^(BOOL finished) {
    [viewSettings removeFromSuperview];
}];

You can read about all the options in Apple's documentation.


removeFromSuperview is not an animatable action, so it is getting performed immediately. Once you commitAnimations, your view is no longer part of it's superview, so you can't see the animation, if it is still even happening.

If you want your animation to happen, then the view to get removed, call removeFromSuperview when the animation ends, such as in a selector specified with setAnimationDidStopSelector:.


Try removing view after the animation is completed. Initially alpha value of the view is 1 then, you apply the animation and make it 0. Now the view is still there but it is not visible. Once the animation is over then remove the view. I think it should work.


I think viewSettings is removed before you commit the animation. Try inverting the two last lines.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜