swift – 在WkWebView iOS中选择图像时,模态视图关闭

我正在构建一个带弹出模式视图的应用程序,其中包含一个WkWebView.当我想在此模态视图中上传图像并出现“照片选择”时,模态视图只会将其反射回启动它的视图控制器.

我怎么能防止这种情况?

import UIKit

class Postwindow : UIViewController {

@IBAction func close(sender: AnyObject) {
    dismissViewControllerAnimated(true,completion: nil)
}

override func viewDidLoad() {
    super.viewDidLoad()
    // do stuff here
    let myWebView:UIWebView = UIWebView(frame: CGRectMake(0,70,UIScreen.mainScreen().bounds.width,UIScreen.mainScreen().bounds.height))
    myWebView.loadRequest(NSURLRequest(URL: NSURL(string: "https://m.facebook.com/")!))
    self.view.addSubview(myWebView)

    self.title = "News Feed"

    UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.Default,animated: true)
    UIApplication.sharedApplication().statusBarHidden = false

    /*let addButton: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Search,target: self,action: #selector(self.openSearch(_:)))
    self.navigationItem.setRightBarButtonItems([addButton],animated: true)*/
    self.navigationController?.navigationBar.tintColor = UIColor.blackColor()
}

override func preferredStatusBarStyle() -> UIStatusBarStyle {
    return UIStatusBarStyle.LightContent
}

}

谢谢!

我遇到了同样的问题.我发现文件上传操作表在选择一个选项时会尝试解除两次,这也会导致模式被解除.

一个解决方案是子类化包含webview的UINavigationController并覆盖dismissViewControllerAnimated以忽略它,除非它实际上有一个presentViewController.

像这样:

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

如果您没有使用导航控制器,请改为在webview中覆盖此方法.

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...