提供一套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

原创粉丝点击