• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Need help animating a view-switch
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Need help animating a view-switch


  • Subject: Need help animating a view-switch
  • From: WT <email@hidden>
  • Date: Fri, 27 Mar 2009 02:47:02 +0100

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]
                    initWithRootViewController: 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 (email@hidden)

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 email@hidden


References: 
 >Avoiding Flicker with OpenGL View when Moving Divider of a Split View (From: Chris Suter <email@hidden>)

  • Prev by Date: User experiencing crash with no report/ log
  • Next by Date: Re: Comparing path strings
  • Previous by thread: Avoiding Flicker with OpenGL View when Moving Divider of a Split View
  • Next by thread: [Solved] Need help animating a view-switch
  • Index(es):
    • Date
    • Thread