IOS下的视图控制器都会有一个presentViewController方法,用来显示模态窗口,在一些特别的环境下我们尤其愿意使用这种窗口,例如临时呈现一些内容时(登录视图、分享列表视图等),所以今天在这里做一下整理。 一、具体设置和使用 1、弹出模态视图窗口(presentViewController方法) 样例代码为: GreenViewController *greenViewController = [[GreenViewController alloc] init]; 方法1:[self presentModalViewControll 方法2:[self presentViewController:greenViewController animated:YES completion:nil]; 两种方法都可以弹出模态视图窗口,方法2使用了block封装,如果在动画弹出模块窗口后有其它的操作,可以使用些方法。 2、弹出风格(UIModalPresentationStyle
UIModalPresentationFullS
UIModalPresentationPageS
UIModalPresentationFormS UIModalPresentationCurrentContext这种模式下,弹出视图控制器的弹出方式和它的父VC的方式相同。
对于iphone或iTouc,只有UIModalPresentationFullS 3、弹出时的动画风格(UIModalTransitionStyle属性)
弹出模态窗口时,如果我们选择了动画显示,那么我们可以通过modalTransitionStyle属性来设置切入动画的风格。 UIModalTransitionStyleFl UIModalTransitionStyleCr UIModalTransitionStylePa 动画风格不受设备的限制,即不管是iPhone还是iPad都会根据我们指定的风格显示转场效果。
4、回收模块视图窗口(dismissModalViewControll 方法一:[self dismissModalViewControll 注:self为弹出的模块视图控制器 总结: 1、每个视图控制器都可以作为模块窗口来显示,但任何时候应用中如果有一个视图控制器被弹出了,那么再弹其它的视图控制器时都不会有效果。 2、模块窗口的显示必需由其它视图控制器调用presentViewController方法来实现;而模块窗口的隐藏(dismiss)是由自己来调用dismissModalViewControll 3、UIModalPresentationFormS - (void)viewDidAppear:(BOOL)animated { 此时模块视图已经根据键盘显示调整到正确的位置,可能由于我们在之前设置模块窗口的bounds GreenViewController *greenViewController = [[GreenViewController alloc] init]; greenViewController .modalPresentationStyle = UIModalPresentationFormS[self presentModalViewControll 这也是没办法的事,目前我还没想到解决方案,如果哪位有好的方案可以留言一起探讨。 |
|