I am trying to animate the appearance and disappearance of two view controllers' view.
I used the following two lines of code:
self.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
[self presentModalViewController:viewcontroller animated:YES];
to make the view controller's view animate in from the bottom of the screen, which works well.
My question is: can I change the style of this animation so that the view isn't always sliding in from the bottom of the screen? How can I make it animate in from the top of the screen, for example?
Yes a presented VC can present another VC.
Use presentViewController:animated:completion: instead.) The default modal presentation style is a card. This shows the previous view controller at the top and allows the user to swipe away the presented view controller. This is the same for both programmatically created and storyboard created controllers.
The UIViewController class defines the shared behavior that's common to all view controllers. You rarely create instances of the UIViewController class directly. Instead, you subclass UIViewController and add the methods and properties needed to manage the view controller's view hierarchy.
The modalTransitionStyle
property on a view controller sets how that view controller will appear, not the animation that it will use to present a different controller. So you'd do something like:
viewcontroller.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
[self presentModalViewController:viewcontroller animated:YES];
(and I'm in the habit of having view controllers dictate their own modal transition style in an overridden initWithCoder:, but that's a style question I guess).
The list of available transition styles is here. So, to try the animation where one controller flips over like a playing card, as if the other were printed on the opposite side:
viewcontroller.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:viewcontroller animated:YES];
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