提供一套modal一个webView控制器的工具类
来源:互联网 发布:华通云数据业界排名 编辑:程序博客网 时间:2024/06/06 14:12
代码:https://github.com/zhangkn/KNUIWebViewWithFileInput
前言
关键词:modal UIWebView and camera/image picker
问题:苹果的一个特性。当模态出N个ViewController之后,只需要dismiss任意一个,都会dismiss它之后的所有模态试图 因此会导致modal模态出来的UIViewController中WebView的H5弹出Camera/ImagePicker 时,当UIDocumentMenuViewController消失的时候会导致WebView 所在的控制器也被干掉。 总的解决思路 所以使dismissViewControllerAnimated调用一次,或者让UIDocumentMenuViewController找不到presentingViewController即可。
基础概念
presentedViewController :The view controller that is presented by this view controller, or one of its ancestors in the view controller hierarchy.
presentingViewController: The view controller that presented this view controller (or its farthest ancestor.)
一、 解决the view controller containing the UIWebView 控制器 被UIDocumentMenuViewController 干掉的问题
1、 问题分析
UIDocumentMenuViewController 消失时调用的不仅调用了自己的,dismissViewControllerAnimated,还调用了,上层或者上上层presentingViewController的dismissViewControllerAnimated。
即会循环调用modal 方式的个个层级的dismissViewControllerAnimated,让所有的控制器消失。
因此当用户选择takePhoto或者photoLibrary的时候,会导致被modal出来的webView 所在的 控制器也会销毁。
二、 问题解决思路
总的解决思路
只让UIDocumentMenuViewController 对象调用自己的dismissViewControllerAnimated,或者让UIDocumentMenuViewController找不到presentingViewController即可。
方法一只让UIDocumentMenuViewController 对象调用自己的dismissViewControllerAnimated,不让加载H5 网页的控制器被刚掉(推荐使用此方法)
当前ViewController的所有presentedViewController都正常执行dismissViewControllerAnimated,当前ViewController本身执行dismissViewControllerAnimated,不进行dismiss,不做处理。
除非用户自己要求退出self.exitKNBaseWebViewControllerflagged = yes 或者 当想dismiss掉当前ViewController的时候,不能调用本身的dismissViewControllerAnimated ,直接调用父类的dismissViewControllerAnimated
重写拥有web View控制器的dismiss 方法
#if 1-(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion{ /**presentedViewController 本控制器即将present展示的控制器 思路,第一次 UIDocumentMenuViewController 展示拍照和photo界面的控制器 消失 第二次 self.presentedViewController nil 此时不调用dismissViewControllerAnimated,, 如果自己要消失的话,需要新增个标识,表示是用户要返回 第三次 UIImagePickerController 相册、拍照控制器 消失 */ if ( self.presentedViewController ) { [super dismissViewControllerAnimated:flag completion:completion]; }// if (self.exitKNBaseWebViewControllerflagged) {// self.exitKNBaseWebViewControllerflagged = NO;// [super dismissViewControllerAnimated:flag completion:completion];// }}#endif
方法二,使UIDocumentMenuViewController找不到presentingViewController
解决方法就是不让UIDocumentMenuViewController找到上层或者上上层的任意presentingViewController
https://github.com/zhangkn/KNUIWebViewWithFileInput.git
设置状态栏字体颜色
方式一:
(在info.plist中,将View controller-based status bar appearance设为YES。View controller-based status bar appearance的默认值就是YES。)
1、在info.plist中,将View controller-based status bar appearance设为NO.
2、在app delegate中:[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
方式二:
1.VC中重写
-(UIStatusBarStyle)preferredStatusBarStyle
2、在viewDidload中调用:[self setNeedsStatusBarAppearanceUpdate];
但是:当vc在nav中时,上面方法没用,vc中的preferredStatusBarStyle方法根本不用被调用。
原因是,[self setNeedsStatusBarAppearanceUpdate]发出后,只会调用navigation controller中的preferredStatusBarStyle方法,vc中的preferredStatusBarStyley方法跟本不会被调用。
解决方法:
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
或者
定义一个nav bar的子类,在这个子类中重写preferredStatusBarStyle方法:
四、CFBundleAllowMixedLocalizations 开启系统预定义的本地化功能
CFBundleAllowMixedLocalizations
- 提供一套modal一个webView控制器的工具类
- modal一个导航控制器
- modal 控制器的样式
- 31.modal方式弹出控制器的view
- 另一种控制器切换的方式→Modal
- android 框架Dileber :五,提供一套免费使用的图标库,超级棒的工具
- 为大家提供一个好的时间工具类DateTime
- 为大家提供一个好的时间工具类DateTime
- 提供一个可用的 lucene 增删改查工具类
- ubuntu 提供一个 一步 设置的 工具
- iOS 手动实现modal效果,从底部弹出一个控制器
- ios 控制器 modal 学习
- a-simple-modal,一个更为简单的modal window。
- Modal出的控制器会引发的内存问题
- ios-modal出来的控制器出现的问题
- iOS - Modal后控制器的关系 及 modal后不移除后面的控件
- iOS自定义Modal视图控制器的转场动画
- 控制器转场动画自定义(2):modal/dismiss的实现
- 逐梦旅程:Windows游戏编程之从零开始 21章源码鼠标移动视角倾斜问题
- 实体类组装json上传
- 剑指offer:数组中1出现的次数
- 导数概念的理解
- linux ssh 不用密码自动登录的几种方法
- 提供一套modal一个webView控制器的工具类
- Leetcode 287 Find the Duplicate Number
- 自己通过编写tag文件来自定义标签
- Spring Boot 事务的使用
- ftp上传下载文件详解
- socket实例
- JavaScript日期字符串和时间戳转换
- 234. Palindrome Linked List(C语言版本)
- 一个好用的沉浸式状态栏以及使用方法