我有一个用户界面,其中SCNView在后台,而WKWebView在前台显示为.popover
。视图由单独的视图控制器控制。当用户按下铃铛按钮时,会出现WKWebView(请参阅随附的屏幕)。 SCNView启用了标准摄像机控制。
目前,当出现WKWebView弹出框时,SCNView变得无法响应。 WKWebView外部的点击手势将其关闭,其他手势将被忽略,因此当WKWebView弹出窗口可见时,用户无法控制SCNView摄像头。 如何在WKWebVIew popover存在的情况下使SCNView响应?只有在按下铃铛按钮时才能解除WKWebView?
下面使用的代码:
class MainVC: UIViewController, UIPopoverPresentationControllerDelegate {
@IBOutlet weak var scnView: SCNView!
@IBOutlet weak var bellBtn: UIButton!
var myWebViewVC: MyWebViewVC!
override func viewDidLoad() {
super.viewDidLoad()
let scene = SCNScene(named: "art.scnassets/DemoScene.scn")!
let scnView = sceneView
scnView!.scene = scene
scnView!.allowsCameraControl = true
}
@IBAction func onBellBtnPressed(_ sender: UIButton) {
myWebViewVC.modalPresentationStyle = .popover
myWebViewVC.popoverPresentationController?.delegate = self
present(myWebViewVC, animated: true, completion: nil)
myWebViewVC.popoverPresentationController?.sourceView = sender
myWebViewVC.popoverPresentationController?.sourceRect = sender.bounds
}
}
MyWebViewVC
只关注视图的大小。文件中没有实现其他自定义修改。
答案 0 :(得分:0)
确定。因此,解决方案主要与视图控制器的popoverPresentationController
参数相关联。这是documentation。要启用对显示为.popover
的视图下方视图的控制,您需要告知其有关当存在弹出窗口时将响应的视图。传球的顺序是从上到下。下面的代码和passThrough
数组使它工作。
class MainVC: UIViewController, UIPopoverPresentationControllerDelegate {
@IBOutlet weak var scnView: SCNView!
@IBOutlet weak var bellBtn: UIButton!
@IBOutlet weak var dotBtn: UIButton!
var myWebViewVC: MyWebViewVC!
override func viewDidLoad() {
super.viewDidLoad()
let scene = SCNScene(named: "art.scnassets/DemoScene.scn")!
scnView!.scene = scene
scnView!.allowsCameraControl = true
}
@IBAction func onBellBtnPressed(_ sender: UIButton) {
activeUiNavigationUnderPopover()
}
func activeUiNavigationUnderPopover () {
myWebViewVC.modalPresentationStyle = .popover
myWebViewVC.popoverPresentationController?.delegate = self
if let pop = myWebViewVC.popoverPresentationController {
var passthroughViews: [AnyObject]?
passthroughViews = [dotBtn, scnView]
pop.passthroughViews = NSMutableArray(array: passthroughViews!) as? [UIView]
pop.permittedArrowDirections = .any
pop.delegate = self
}
present(myWebViewVC, animated: true, completion: nil)
myWebViewVC.popoverPresentationController?.sourceView = sender
myWebViewVC.popoverPresentationController?.sourceRect = sender.bounds
}
}