views:

132

answers:

1

So, I've searched quite a bit for this and can't seem to find a solution.

This code works:

CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationDuration:5];
[c setCenter:CGPointMake(200, 200)];
[UIView commitAnimations];

This code doesn't:

CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:c cache:YES];
[UIView setAnimationDuration:5];
[c exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
[UIView commitAnimations];

And I know the call to exchangeSubViewAtIndex is working because if I remove it from the animation block it functions as expected.

Anyone have any insight as to why this transition won't run? Something I need to import?

+1  A: 

I’ll quote Apple (again) here:

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 you probably would like to use removeFromSuperview & addSubView: instead of exchanging two subviews if you were using a predefined transition.

Evadne Wu
Yeah, that's the pattern I followed. And I get the same result from remove and add as opposed to exchanging.
derrickp