This is an iPad project where I have a UIView with several subViews, and I am trying to animate one of this UIViews using [UIView transitionFromView:toView:duration:options:completion], but when I run this method the whole parent view gets flipped! This is the code I'm using:
UIView *secondView = [[UIView alloc] initWithFrame:CGRectMake(200, 200, 300, 300)]; [newView setBackgroundColor:[UIColor redColor]]; [UIView transitionFromView:self.firstView.view toView:secondView duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil];
Any idea on how can I flip between this views without animating the whole parent view? Thanks!
this code may helps you:
put the two views you want to flip inside an unnamed view with the same size and link the IBOutlet UIView *newView,*oldView;
to the views and put the new view on top
bool a = NO; @implementation ViewController - (IBAction)flip:(id)sender { if (a == NO) { [UIView transitionFromView:oldView toView:newView duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft completion:NULL]; a = YES; // a = !a; } else { [UIView transitionFromView:newView toView:oldView duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft completion:NULL]; a = NO; // a = !a; } }
I had problems getting this to work also. I used the code written by Floris, but although it worked for the first "flip" the next flip started to go weird where the buttons and labels on the frontside UI View lost there positions.
I put the code below into place and it is working fine.
Couple of things to note:
(in my .h)
@property BOOL displayingFront;
in my .m
@synthesize displayingFront;
in my viewDidLoad method
self.displayingFront = YES;
This is the code in the .m that i have rigged up to the two buttons if front and back UIViews...
- (IBAction)flip:(id)sender { [UIView transitionWithView:self.panelView duration:1.0 options:(displayingFront ? UIViewAnimationOptionTransitionFlipFromRight : UIViewAnimationOptionTransitionFlipFromLeft) animations: ^{ if(displayingFront) { self.frontView.hidden = true; self.backView.hidden = false; } else { self.frontView.hidden = false; self.backView.hidden = true; } } completion:^(BOOL finished) { if (finished) { displayingFront = !displayingFront; } }]; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With