【发布时间】:2018-03-05 06:10:19
【问题描述】:
我有一个具有按钮属性的自定义 UIView,我想向它添加一个操作以在应用程序中打开 webview。为此,我想使用 SFSafariViewController。这是我试图实现这一目标的方法。
import UIKit
import SafariServices
class CustomViewScreen: UIView, SFSafariViewControllerDelegate {
@IBAction func privacyNoteBtnAction(_ sender: UIButton) {
if #available(iOS 9.0, *) {
let urlString = "https://stackoverflow.com/"
if let url = URL(string: urlString) {
let vc = SFSafariViewController(url: url, entersReaderIfAvailable: true)
vc.delegate = self
UIApplication.shared.keyWindow?.rootViewController?.present(vc, animated: true, completion: nil)
}
} else {
// Fallback on earlier versions
}
}
func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
controller .dismiss(animated: true, completion: nil) // also not able to trigger this method when i tap "Done"
}
我什至不能正确使用这种方式,因为我得到“谁的视图不在窗口层次结构中!”我也无法在点击“完成”按钮后调用 SFSafariViewControllerDelegate 方法来关闭视图。我在 UIView 中时有什么想法可以采取行动,或者有什么想法可以将此动作连接到我的主控制器以使用正确的呈现方法?
【问题讨论】:
-
你只能在另一个视图控制器上呈现视图控制器......你不能在视图中呈现视图控制器......相反你可以添加其他视图控制器的子视图......跨度>
-
发生了什么
self.present(
标签: ios swift uiwebview webkit sfsafariviewcontroller