Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to change the animation style of a modal view controller appearance?

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?

like image 572
ajay Avatar asked Feb 15 '11 13:02

ajay


People also ask

Can a presented view controller also be a presenting view controller?

Yes a presented VC can present another VC.

How do you present a modal view controller programmatically?

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.

What is a UIViewController?

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.


1 Answers

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];
like image 149
Tommy Avatar answered Sep 28 '22 08:09

Tommy