Why disappear a ViewController's view when you are displaying it? Looks backwards.
I'm in the process of learning iOS and working through an example - which I mostly understand. Here's some code which I'll follow up with a question:
- (IBAction) switchViews:(id)sender{
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
if (self.yellowViewController.view.superview == nil) {
if (self.yellowViewController == nil) {
YellowViewController *yellowController = [[YellowViewController alloc] initWithNibName:@"YellowView" bundle:nil];
self.yellowViewController = yellowController;
[yellowController release];
}
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[blueViewController viewWillAppear:YES];
[yellowViewController viewWillDisappear:YES];
[blueViewController.view removeFromSuperview];
[self.view insertSubview:yellowViewController.view atIndex:0];
[yellowViewController viewDidDisappear:YES];
[blueViewController viewDidAppear:YES];
Here's what I understand. The animation is clear.
We're checking to see if yellowViewController is displayed. If not then we check and see if it's instantiated. If not, we instantiate it and then display it, first removing blueViewController from the SuperView.
All good so far.
Here's what I don't understand - why are doing the following:
[blueViewController viewWillAppear:YES];
[y开发者_如何转开发ellowViewController viewWillDisappear:YES];
It seems to me we should Disappear the blueViewController and not the Yellow.
I'd really appreciate an explanation. Thanks.
You should not be making these calls yourself, they are made automatically by the iOS framework. Thus all of your viewWill…
and viewDid…
calls are unnecessary and can be removed.
精彩评论