开发者

Close Animation will not run

In my iPhone app there is a window that appears开发者_C百科 over the main window. Here is the code for my close button;

-(IBAction)cancel{
[UIView beginAnimations:@"Animation" context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[self.view removeFromSuperview]; 
//[_window addSubview:view2];
[UIView commitAnimations];}

The window closes correctly but the animation will not execute. I do not understand why.

thanks


I think it is because you are removing the view from the superview during the animation. The animation does not occur because the view is gone. You should wait until after the animation finishes to remove to view, which you can do by setting a delegate and selector which is called when the animation is finished.

[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

And then in

-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
    [self.view removeFromSuperview];
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜