7

現在、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
}

}

ありがとう!

4

3 に答える 3

13

同じ問題が発生しました。オプションを選択すると、ファイル アップロード アクション シートがそれ自体を 2 回閉じようとするため、モーダルも閉じられることがわかりました。

UINavigationController解決策は、webview を含むをサブクラス化し、オーバーライドdismissViewControllerAnimatedして、実際にpresentedViewController.

そのようです:

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

ナビゲーション コントローラーを使用していない場合は、代わりに webview でこのメソッドをオーバーライドしてください。

于 2016-07-07T14:51:00.867 に答える