Reputation: 1177
So I have a button with an IBAction
which is supposed to display a subview
. The view
is in the storyboard and I'm calling it was instantiateViewController
. This works fine. I would like to animate the views transition onto the screen which is where I hit this problem. The following code is what I have however all it does is display the entire view
at once but without text on buttons etc. and then drags the text down from the top. Quite obscure. Commenting out the setAnimationTransition
line heralds the same result.
MapViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"MapViewController"];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:MapViewController.view cache:YES];
[self.view addSubview:MapViewController.view];
[UIView commitAnimations];
Anybody have any ideas?
Your help is much appreciated.
Thanks.
As per the comment below I have changed it to:
[UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{[self.view addSubview:MapViewController.view];} completion:NULL];
However the problem still persists.
Upvotes: 0
Views: 1680
Reputation: 1177
[UIView transitionWithView:containerView duration:0.5
options:UIViewAnimationOptionTransitionCurlUp //change to whatever animation you like
animations:^ { [containerView addSubview:subview]; }
completion:nil];
Seemed to work.
Upvotes: 1
Reputation: 130092
Change
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:MapViewController.view
cache:YES];
to
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:self.view
cache:YES];
You are not animating the view you add, you animate the container...
Also note that this set of methods is deprecated and if you are not targetting iOS < 4.0, you should use the block-based animation methods instead.
Don't use UIViewAnimationOptionTransitionFlipFromRight
, that's only for the block-based methods (see Akash's answer).
Upvotes: 0
Reputation: 8320
Try this :
[UIView transitionWithView:self.view
duration:0.5
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^{
[self.view addSubview:MapViewController.view];
}
completion:nil];
Upvotes: 1