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];
}
精彩评论