derrickp
derrickp

Reputation: 203

UIView Animation won't run transition

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?

Upvotes: 1

Views: 820

Answers (1)

Evadne Wu
Evadne Wu

Reputation: 3200

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.

Upvotes: 1

Related Questions