您的位置:首页 > Web前端 > CSS

模态视图那些事(二)之 弹出视图样式

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时的风格,有以下四种风格,其定义如下:

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:^{

// 可以在这里写需要调用的方法

}];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息