模态显示PresentModalViewController
1、主要用途
- 弹出模态ViewController是IOS变成中很有用的一个技术,UIKit提供的一些专门用于模态显示的ViewController,如UIImagePickerController等。弹出模态ViewController
主要使用于一下这几种情形:
- 1、收集用户输入信息
- 2、临时呈现一些内容
- 3、临时改变工作模式
- 4、相应设备方向变化(用于针对不同方向分别是想两个ViewController的情况)
- 5、显示一个新的view层级
- 这几种情形都会暂时中断程序正常的执行流程,主要作用是收集或者显示一些信息。
2、弹出方法:presentModalViewController:
- 由 视图控制器类对象调用presentModalViewController: 方法。
- 以模态窗口的形式管理视图,当前视图关闭前其他视图上的内容无法操作。
3、modalTransitionStyle属性
- 通过设置设置presenting VC的modalTransitionStyle属性,我们可以设置弹出presented VC时场景切换动画的风格,包含类型如下:
typedef enum {
UIModalTransitionStyleCoverVertical, // 自下而上(从底部滑入)
UIModalTransitionStyleFlipHorizontal, // 自左至右180度翻转(水平翻转进入)
UIModalTransitionStyleCrossDissolve, // 淡出效果(交叉溶解)
UIModalTransitionStylePartialCurl // 翻页效果
} UIModalTransitionStyle;
- 这四种风格在不受设备的限制,即不管是iPhone还是iPad都会根据我们指定的风格显示转场效果。
4、Modal Presentation Styles(弹出风格)
- 通过设置presenting VC的modalPresentationStyle属性,我们可以设置弹出View Controller时的风格,有以下四种风格,其定义如下:
typedef enum {
UIModalPresentationFullScreen = 0,
UIModalPresentationPageSheet,
UIModalPresentationFormSheet,
UIModalPresentationCurrentContext,
} UIModalPresentationStyle;
4.1 UIModalPresentationFullScreen
- 代表弹出VC时,presented VC充满全屏,如果弹出VC的wantsFullScreenLayout设置为YES的,则会填充到状态栏下边,否则不会填充到状态栏之下。
4.2 UIModalPresentationPageSheet
- 代表弹出是弹出VC时,presented VC的高度和当前屏幕高度相同,宽度和竖屏模式下屏幕宽度相同,剩余未覆盖区域将会变暗并阻止用户点击,这种弹出模式下,竖屏时跟UIModalPresentationFullScreen的效果一样,横屏时候两边则会留下变暗的区域。
4.3 UIModalPresentationFormSheet
- 这种模式下,presented VC的高度和宽度均会小于屏幕尺寸,presented VC居中显示,四周留下变暗区域。
4.4 UIModalPresentationCurrentContext
- 这种模式下,presented VC的弹出方式和presenting VC的父VC的方式相同。
- 这四种方式在iPad上面统统有效,但在iPhone和iPod touch上面系统始终已UIModalPresentationFullScreen模式显示presented VC。
5、关闭方法:dismissModalViewControllerAnimated:
- 由 视图控制器类对象调用dismissModalViewControllerAnimated: 方法。
6、获取不同的模态窗口(主要的属性)
@property(nonatomic, readonly) UIViewController *presentedViewController ; // 当前控制器模态出的窗口
@property(nonatomic, readonly) UIViewController *presentingViewController; // 模态出当前控制器的窗口
7、处理模态窗口(主要的方法)
// 显示想要显示的模态窗口
- (void)presentViewController:(UIViewController *)viewControllerToPresent
animated: (BOOL)flag
completion:(void (^)(void))completion);
// 关闭当前显示的模态窗口
- (void)dismissViewControllerAnimated: (BOOL)flag
completion: (void (^)(void))completion);
// 当前控制器模态另一个窗口并传输数据时调用的方法
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)
8、使用提醒
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中实现该代理,这样就可以比较方便的实现两者之间的交互。
9、示例
ModalTestController *vc = [[ModalTestController alloc] init];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
vc.hidesBottomBarWhenPushed = YES;
UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:vc];
navi.definesPresentationContext = YES;
navi.modalPresentationStyle = UIModalPresentationCurrentContext;
[self.navigationController presentViewController:navi animated:YES completion:^{
navi.navigationBarHidden = YES;
}];
模态显示PresentModalViewController的更多相关文章
- IOS疯狂基础之模态显示PresentModalViewController(转)
转自:http://blog.csdn.net/wudizhukk/article/details/8553554 -(void)buttonDown:(id)sender{ ViewTwo *two ...
- div模态显示内容
业务需要,上传的图片,本地显示大图: 模态代码: <div onclick="hidebigimg()" class = "bg-model" style ...
- 关于iPad上模态显示视图中的UITextField,UITextView在输入完成后无法回收键盘的问题解决。
在iPad开发过程中遇到一个问题,UITextField 存在由UIModalPresentationFormSheet 弹出的带导航条的视图控制器中时,调用 resignFirstResponder ...
- 弹出视图/弹出模态presentViewController与presentModalViewController
一.主要用途 弹出模态ViewController是IOS变成中很有用的一个技术,UIKit提供的一些专门用于模态显示的ViewController,如UIImagePickerController等 ...
- iOS:视图切换的第一种方式:模态窗口
一.UIModalController:模态窗口(一个控制器模态出另一个控制器的模态窗口) 当我们在view controller A中模态显示view controller B的时候,A就充当pre ...
- IOSView显示特性设置
一.主要用途 弹出模态ViewController是IOS变成中很有用的一个技术,UIKit提供的一些专门用于模态显示的ViewController,如UIImagePickerController等 ...
- QT笔记之模态对话框及非模态对话框
模态对话框(Modal Dialog)与非模态对话框(Modeless Dialog)的概念不是Qt所独有的,在各种不同的平台下都存在.又有叫法是称为模式对话框,无模式对话框等.所谓模态对话框就是在其 ...
- iOS:模态弹出窗控制器UIPopoverPresentationController
模态弹出窗控制器:UIPopoverPresentationController 实质:就是将内容控制器包装成PopoverPresentationController的形式,然后再模态出来,必须指定 ...
- QT模态弹出对话框
QDialog QWidget 默认show()都是非模态 如果需要模态显示, QDialog ==> setModal(true); show(); exec(); QWidget ==> ...
随机推荐
- 微信小程序之工具js封装与使用
工具库的创建与使用 创建一个common文件夹 在common文件夹中创建一个utils文件夹 在utils文件夹中创建util.js // 工具 function tool() { console. ...
- 使用QuartZ.net来做定时计划任务 ; 值不能为 null。 参数名: assemblyString
1. 当异常的时候, 发现需要的类名, 没有取到, 然后就发生异常了 2. 分析: 业务层调用数据层, 数据层去掉配置的时候, 发现配置文件中根本就没有配置, 这个时候使用反射来取, 肯定是拿不到的, ...
- Build Assetbundle出错:An asset is marked as dont save, but is included in the build
前天Build Assetbundle的时候出错了,导致打包失败,具体日志内容如下: An asset is marked as dont save, but is included in the b ...
- oracle导入数据和编码问题
配置contrl文件 load data characterset utf8 append into table role_res_gold fields terminated by ';' TRAI ...
- ADO.NET主要组件
- 解决The JSP specification requires that an attribute name is preceded by whitespace问题
笔者今天调试界面出现下边这个问题: The JSP specification requires that an attribute name is preceded by whitespace 经查 ...
- oracle:RETURNING 子句
RETURNING 自己通常结合DML 语句使用.(INSERT UPDATE DELETE) 使用方法: UPDATE table_name SET expr1 RETURNING column_n ...
- C#使用 SharpAVI进行 屏幕录制
再 nuget 中 搜索 shapAvi 并添加引用 github 地址:https://github.com/baSSiLL/SharpAvi using SharpAvi; using Sharp ...
- Redis搭建(五):Cluster集群搭建
一.方案 1. 介绍 redis3.0及以上版本实现,集群中至少应该有奇数个节点,所以至少有三个节点,官方推荐三主三从的配置方式 使用哈希槽的概念,Redis 集群有16384个哈希槽,每个key通过 ...
- js如何解析后台传过来的json字符串
1.js如何解析后台传过来的json字符串? 注意:js是无法直接接收和使用json或者Php的数据,用的话会出现undefined,所以要转换一下. 方式一: var str = '{"r ...