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

ε祈祈猫儿з 提交于 2019-12-07 01:44:18

问题


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?


回答1:


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];


来源:https://stackoverflow.com/questions/5004102/is-there-a-way-to-change-the-animation-style-of-a-modal-view-controller-appearan

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!