模态视图那些事(二)之 弹出视图样式
2016-06-17 10:25
489 查看
1、presenting view controller Vs presented view controller
当我们在view controller A中模态显示view controller B的时候,A就充当presenting view controller(弹出VC),而B就是presented view controller(被弹出VC)。官方文档建议这两者之间通过delegate实现交互,如果使用过UIImagePickerController 从系统相册选取照片或者拍照,我们可以发现imagePickerController和弹出它的VC之间就是通过 UIImagePickerControllerDelegate实现交互的。因此我们在实际应用用,最好也遵守这个原则,在被弹出的VC中定义
delegate,然后在弹出VC中实现该代理,这样就可以比较方便的实现两者之间的交互。
2、Modal Presentation Styles(弹出风格)
通过设置presenting VC的modalPresentationStyle属性,我们可以设置弹出View Controller时的风格,有以下四种风格,其定义如下:
UIModalPresentationFullScreen代表弹出VC时,presented VC充满全屏,如果弹出VC的wantsFullScreenLayout设置为YES的,则会填充到状态栏下边,否则不会填充到状态栏之下。
UIModalPresentationPageSheet代表弹出是弹出VC时,presented VC的高度和当前屏幕高度相同,宽度和竖屏模式下屏幕宽度相同,剩余未覆盖区域将会变暗并阻止用户点击,这种弹出模式下,竖屏时跟 UIModalPresentationFullScreen的效果一样,横屏时候两边则会留下变暗的区域。
UIModalPresentationFormSheet这种模式下,presented VC的高度和宽度均会小于屏幕尺寸,presented VC居中显示,四周留下变暗区域。
UIModalPresentationCurrentContext这种模式下,presented VC的弹出方式和presenting VC的父VC的方式相同。
这四种方式在iPad上面统统有效,但在iPhone和iPod touch上面系统始终已UIModalPresentationFullScreen模式显示presented VC。
3、iOS 8 以后添加了一个样式UIModalPresentationOverCurrentContext
定义如下:
弹出之后,我们就需要让他消失,一般情况下,我们使用下面这个方法:
当我们在view controller A中模态显示view controller B的时候,A就充当presenting view controller(弹出VC),而B就是presented view controller(被弹出VC)。官方文档建议这两者之间通过delegate实现交互,如果使用过UIImagePickerController 从系统相册选取照片或者拍照,我们可以发现imagePickerController和弹出它的VC之间就是通过 UIImagePickerControllerDelegate实现交互的。因此我们在实际应用用,最好也遵守这个原则,在被弹出的VC中定义
delegate,然后在弹出VC中实现该代理,这样就可以比较方便的实现两者之间的交互。
2、Modal Presentation Styles(弹出风格)
通过设置presenting VC的modalPresentationStyle属性,我们可以设置弹出View Controller时的风格,有以下四种风格,其定义如下:
typedef enum { UIModalPresentationFullScreen = 0, UIModalPresentationPageSheet, UIModalPresentationFormSheet, UIModalPresentationCurrentContext, } UIModalPresentationStyle;
UIModalPresentationFullScreen代表弹出VC时,presented VC充满全屏,如果弹出VC的wantsFullScreenLayout设置为YES的,则会填充到状态栏下边,否则不会填充到状态栏之下。
UIModalPresentationPageSheet代表弹出是弹出VC时,presented VC的高度和当前屏幕高度相同,宽度和竖屏模式下屏幕宽度相同,剩余未覆盖区域将会变暗并阻止用户点击,这种弹出模式下,竖屏时跟 UIModalPresentationFullScreen的效果一样,横屏时候两边则会留下变暗的区域。
UIModalPresentationFormSheet这种模式下,presented VC的高度和宽度均会小于屏幕尺寸,presented VC居中显示,四周留下变暗区域。
UIModalPresentationCurrentContext这种模式下,presented VC的弹出方式和presenting VC的父VC的方式相同。
这四种方式在iPad上面统统有效,但在iPhone和iPod touch上面系统始终已UIModalPresentationFullScreen模式显示presented VC。
3、iOS 8 以后添加了一个样式UIModalPresentationOverCurrentContext
定义如下:
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
nextVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
} else {
self.modalPresentationStyle = UIModalPresentationCurrentContext;
}
弹出之后,我们就需要让他消失,一般情况下,我们使用下面这个方法:
[self dismissViewControllerAnimated:YES completion:^{
// 可以在这里写需要调用的方法
}];
相关文章推荐
- Html+CSS绘制三角形图标
- 用CSS隐藏页面元素的5种方法
- html+css——<q>标签
- css——浏览器前缀
- CSS中padding和margin的区别
- [CSS] DOM Hierarchy Pseudo Classes :first-child :last-child :nth-child (demystified)
- DIV+CSS布局
- z-index不起作用
- (10)用css建立表单
- css揭秘之按钮的实现技巧
- 网页样式混乱
- css揭秘之linear-gradient
- CSS3的笔记总结
- html——样式、链接和表格
- 设置input获得焦点边框样式
- 【CSS进阶】box-shadow 与 filter:drop-shadow 详解及奇技淫巧
- 样式总结
- html基础介绍、基础标签以及文字样式
- CSS块级元素和内联元素
- css——如何让一段文字自动换行,并且左对齐,设置背景透明