我有一个使用 WKWebView 的 macOS 应用程序。我以编程方式克隆该 WebView 以获取另一个 View 。但是当我尝试将新约束设置为等于主 WebView 时,如下所示
NSLayoutConstraint(item: copiedWebView, attribute: .centerY, relatedBy: .equal, toItem: self.webView, attribute: .centerY, multiplier: 1.0, constant: 0.0).isActive = true
NSLayoutConstraint(item: copiedWebView, attribute: .height, relatedBy: .equal, toItem: self.webView, attribute: .height, multiplier: 1.0, constant: 0.0).isActive = true
NSLayoutConstraint(item: copiedWebView, attribute: .centerX, relatedBy: .equal, toItem: self.webView, attribute: .centerX, multiplier: 1.0, constant: 0.0).isActive = true
NSLayoutConstraint(item: copiedWebView, attribute: .width, relatedBy: .equal, toItem: self.webView, attribute: .width, multiplier: 1.0, constant: 0.0).isActive = true
两个 WebView 都无法拖放某些内容。
更新
奇怪...当我设置高度约束时...active = false
拖放工作正常。约束是否与原始 webView 或主视图相关也并不重要。
最佳答案
好吧。我找出了问题所在:WebView – 即使 isHidden = true
“在技术上分层在原始 WebView 之上”——因此,当切换事件 WebView 时,我需要将 View 置于前面。
这与约束本身无关。
关于swift - WKWebView无法拖动Element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58697209/