Modal view closes when selecting an image in WkWebView iOS

泪湿孤枕 提交于 2019-11-29 07:03:34
Tom Durrant

I encountered the same issue. I found that the file upload action sheet tries to dismiss itself twice upon selecting an option, which results in the modal being dismissed as well.

A solution is to subclass the UINavigationController containing the webview and override dismissViewControllerAnimated to ignore it unless it actually has a presentedViewController.

Like so:

override func dismissViewControllerAnimated(flag: Bool, completion: (() -> Void)?) {
    if (self.presentedViewController != nil) {
        super.dismissViewControllerAnimated(flag, completion: completion)
    }
}

If you're not using a navigation controller, just override this method in the webview instead.

It also works for non NavigationController / ViewController only in this way:

override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil){
    if(self.presentedViewController != nil) 
    {
        super.dismiss(animated: flag, completion: completion)
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!