BeginAnimations and CommitAnimations with NavigationController.PushViewController

4.2k views Asked by At

I'm trying to get a basic flip animation transition working when I push a controller inside a navigation. The code below flips the view, however the view appears first (each element fades in), and then the flip occurs. Is it possible to do a flip animation with a UINavigationController?

Any pointers would be great, the examples I've found for Monotouch are performing animations on Views inside another view.

void ToolbarButtonClick()
{
    InformationController controller = new InformationController();
    NavigationController.PushViewController(controller,true);
}

public class InformationController : UIViewController
{
    public override void ViewDidLoad ()
    {
        UIView.BeginAnimations("Flip");
        UIView.SetAnimationDuration(1.0);
        UIView.SetAnimationTransition(UIViewAnimationTransition.FlipFromRight,View,true);

        base.ViewDidLoad ();
        Title = "Information";
    }

    public override void ViewWillAppear (bool animated)
    {
        base.ViewWillAppear (animated);
    }

    public override void ViewDidAppear (bool animated)
    {
        base.ViewDidAppear (animated);
        UIView.CommitAnimations();
    }
}
2

There are 2 answers

0
Chris S On BEST ANSWER

I was sort of there, but the View needs to be taken from the NavigationController:

// Push the controller first or the Title doesn't animate
NavigationController.PushViewController(controller,false);

UIView.BeginAnimations(null,IntPtr.Zero);
UIView.SetAnimationDuration(1);
UIView.SetAnimationTransition(UIViewAnimationTransition.FlipFromLeft,
                              NavigationController.View,true);
UIView.CommitAnimations();
1
Driss Zouak On

I'm not an expert, but I'm wondering about that TRUE on the PushViewcontroller which indicates that it is going to be animated. It has me wondering if that is making the NavigationController do the initial amount of animation work, which is then followed by yours. When you set it to false, what happens? I know we tend to automatically put the TRUE in there without thinking.