Subject: Need help animating a view-switch



Hello,

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.

Wagner

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;

switch (viewControllerType)
{
case kViewControllerTypeIntroViewController:
{
if (introViewController == nil)
{
self.introViewController = [[IntroViewController alloc]
initWithRootViewController: self];
}

newViewController = introViewController;
}
break;

case kViewControllerTypeInfoViewController:
{
if (infoViewController == nil)
{
self.infoViewController = [[InfoViewController alloc]
initWith...

RootViewController: self];
}

newViewController = infoViewController;
}
break;

// More cases here...

default: /* do nothing */
return;
}

// curViewController is nil the very first time this method is executed
if (curViewController)
{
[UIView beginAnimations: @"view switch" context: nil];
[UIView setAnimationDuration: 1.5];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft
forView: curViewController.view cache: YES];

[curViewController viewWillDisappear: YES];
[newViewController viewWillAppear: YES];

[curViewController.view.superview
insertSubview: newViewController.view atIndex: 0];

[curViewController.view removeFromSuperview];

[curViewController viewDidDisappear: YES];
[newViewController viewDidAppear: YES];

[UIView commitAnimations];
}

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:
http://lists.apple.com/mailman/options/cocoa-dev/maillists%40codeha.us

This email sent to maillists@xxxxxxxxx



Privacy