Reputation: 1490
I am currently working through a beginners guide to programming for ios6. It's been fine until just now when I tried to animate switching back and forth between two views. The final goal of the exercise was to have it seem as if each view was on the back of the other (like the sides of a coin/piece of paper).
However, when I use the code given in the book, only one of the animations activates but the book says that the code should work for both.
I have been over my code multiple times to make sure that I have done it right and I have not been able to distinguish a difference between the code that I have and the code that is in the book. I know that it's something simple that I am doing (or more likely not doing) but I just don't have the experience to find it.
Any help would be very much appreciated.
Code:
- (IBAction)switchViews:(id)sender
{
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:1.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
if (self.yellowViewController.view.superview == nil) {
if (self.yellowViewController == nil) {
self.yellowViewController = [[BIDYellowViewController alloc] initWithNibName:@"YellowView" bundle:nil];
}
// This one doesn't work
[UIView setAnimationTransition:UIViewAnimationOptionTransitionFlipFromRight forView:self.view cache:YES];
[self.blueViewController.view removeFromSuperview];
[self.view insertSubview:self.yellowViewController.view atIndex:0];
}
else
{
if (self.blueViewController == nil) {
self.blueViewController = [[BIDBlueViewController alloc] initWithNibName:@"BlueView" bundle:nil];
}
// This one works
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
[self.yellowViewController.view removeFromSuperview];
[self.view insertSubview:self.blueViewController.view atIndex:0];
}
[UIView commitAnimations];
}
Upvotes: 1
Views: 1640
Reputation: 1735
Its because you use UIViewAnimationOptionTransitionFlipFromRight
instead of UIViewAnimationTransitionFlipFromRight
Upvotes: 2