views:

271

answers:

4

I have the following code to do a UIView animation:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:mapView.view cache:NO];
[self addSubview:detailView];
[mapView removeFromSuperview];
[UIView commitAnimations];

It works when I dont add the detailView. What actually happens is the equivalent of this:

[self addSubview:detailView];
[mapView removeFromSuperview];
+1  A: 

i think you have the order wrong. you need to remove the old subview first before adding the new one.

see reference for setAnimationTransition:forView:cache:

you can also use CATransition on the layer of a view. and then use layer animations.

if you specifically want to flip the new view you can also use presentalModalViewController method of uiviewcontroller.

Remover
A: 

I had to set the graphics context to UIGraphicsGetCurrentContext()

agentfll
A: 

I have seen your code in tutorials all the time and never works for me. I always use this:

UIViewController *mainViewController = [[YourMainViewController alloc] init];
UIViewController *viewControllerToSwitchTo = [[ViewControllerToSwitchTo alloc] init];

[mainViewController presentModalViewController:viewControllerToSwitchTo animated: YES];

you can set the view changing style with:

[setModalTransitionStyle:WhateverModalTransitionStyleYouWant];

but make sure this goes before the transition method.

Mark Szymanski
A: 

That code won't work. From Apple's documentation:

If you want to change the appearance of a view during a transition—for example, flip from one view to another—then use a container view, an instance of UIView, as follows:

  1. Begin an animation block.
  2. Set the transition on the container view.
  3. Remove the subview from the container view.
  4. Add the new subview to the container view.
  5. Commit the animation block.

So the transition should be applied to self not your mapView, and your add/remove are in reverse order.

Steven Fisher