[英]Cursor isn’t changed properly when drag a file to a draggable view on Cocoa's WKWebView
I wrote the following code to put a draggable view on WKWebView. 我编写了以下代码,以将可拖动视图放在WKWebView上。
With this code, I expected a "+" icon will be displayed nearby a cursor when I dragged a file to the view. 使用此代码,当我将文件拖动到视图时,我希望光标附近会显示一个“ +”图标。
class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
let rect = NSRect(x: 0, y: 0, width: 200, height: 200)
let webView = WKWebView(
frame: rect,
configuration: WKWebViewConfiguration())
webView.load(URLRequest(
url: URL(string: "https://i.imgur.com/D5ru3Q7.jpg")!))
let draggableView = DraggableView(frame: rect)
draggableView.registerForDraggedTypes([.fileURL])
self.view.addSubview(webView)
self.view.addSubview(draggableView)
}
}
class DraggableView: NSView {
override func draggingEntered(_ sender: NSDraggingInfo) -> NSDragOperation {
return .copy
}
}
The result is here: 结果在这里:
I think the webView
prevents the cursor changing. 我认为
webView
可以防止更改光标。 So I tried the followings. 因此,我尝试了以下方法。 But I couldn't fix.
但是我无法解决。
hitTest
of the webView worked only for non-dragging mouse over actions. hitTest
仅适用于非拖动鼠标悬停操作。 But not for dragging. webView.unregisterDraggedTypes()
didn't work. webView.unregisterDraggedTypes()
不起作用。 Is there anyway to fix this? 有没有什么办法解决这一问题?
Found a solution: 找到了解决方案:
for t in webView.trackingAreas {
webView.removeTrackingArea(t)
}
I think removing tracking areas on a web view is not a good idea. 我认为删除Web视图上的跟踪区域不是一个好主意。 But at least it satisfies my need.
但这至少可以满足我的需求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.