首页 > 解决方案 > 禁用 SFSafariViewController 的下拉解散

问题描述

是否可以禁用下拉解除手势SFSafariViewController

似乎SFSafariViewController在它自己的窗口中运行,因此,设置isModalInPresentation甚至设置presentationControllerShouldDismiss(_:)似乎没有任何作用。

SFSafariViewController 文档似乎也没有在这里指定任何内容。

MWE:

import SafariServices
import UIKit

class ViewController: UIViewController, UIAdaptivePresentationControllerDelegate {
    override func viewDidLoad() {
        super.viewDidLoad()

        DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
           let vc = SFSafariViewController(url: URL(string: "https://stackoverflow.com")!)
            vc.modalPresentationStyle = .pageSheet
            // `presentationControllerShouldDismiss` will be ignored, if isModalInPresentation is set to `true`
            // vc.isModalInPresentation = true
            vc.presentationController?.delegate = self

            self.present(vc, animated: true)
        }
    }

    func presentationControllerShouldDismiss(_ presentationController: UIPresentationController) -> Bool {
        return false
    }

    func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
        NSLog("Did dismiss")
    }
}

标签: iosswiftsfsafariviewcontroller

解决方案


推荐阅读