我有一个使用WKWebView的macOS应用。我以编程方式克隆该WebView以获得另一个视图。但是当我尝试将新约束设置为等于主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时,我需要将视图置于最前面。
与约束本身无关。