Subject: Need help animating a view-switch
I'm writing a multi-view application for the iPhone, so I set up a
root view controller and several other view controllers. The root view
controller's view is actually set at all times to the view of the
currently active view controller, so the application delegate doesn't
need to know which view controller is active.
Now, I want to have an animated transition when views get switched,
and I have the following method (in the root view controller's class)
that is called on the root view controller by any of the other view
controllers when they process an event that requires a view switch.
The method works fine as far as causing the switch, but there is no
animation and I can't see what I'm doing wrong. I'd appreciate if
anyone could shed some light and show me the way.
Thanks in advance.
PS. Apologies if this post violates any list rules regarding
discussions of iPhone development. I would think not, given that this
question is really about animating views and it involves information
that is openly available in books (my code is based on code from
"Beginning iPhone Development" by Dave Mark).
- (void) switchToViewController: (ViewControllerType) viewControllerType
UIViewController* newViewController = nil;
if (introViewController == nil)
self.introViewController = [[IntroViewController alloc]
newViewController = introViewController;
if (infoViewController == nil)
self.infoViewController = [[InfoViewController alloc]
newViewController = infoViewController;
// More cases here...
default: /* do nothing */
// curViewController is nil the very first time this method is
[UIView beginAnimations: @"view switch" context: nil];
[UIView setAnimationDuration: 1.5];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
forView: curViewController.view cache:
[curViewController viewWillDisappear: YES];
[newViewController viewWillAppear: YES];
insertSubview: newViewController.view atIndex: 0];
[curViewController viewDidDisappear: YES];
[newViewController viewDidAppear: YES];
self.view = newViewController.view;
curViewController = newViewController;
Cocoa-dev mailing list (Cocoa-dev@xxxxxxxxxxxxxxx)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to maillists@xxxxxxxxx