Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I move the window without titleBar and fully filled with webView?

Tags:

macos

swift

cocoa

I'm working on something similar to the native picture in picture.

My window

I want to move this window, but can't because there is no titlebar (it's hidden and window.stylemask is fullSizeContentView) in it and it's fully filled with the webView.

So, I can't just click on titlebar and drag to move this window.

P.S. Sorry for my english. I hope the goal is clear

like image 341
Роман Елизаров Avatar asked Dec 22 '16 15:12

Роман Елизаров


1 Answers

You can subclass the webview to catch -mouseDown: events, and then pass the NSEvent to -[NSWindow performWindowDragWithEvent:].

Apple has sample code which uses this technique to start a window drag after the mouse moves some minimum distance, while still handling normal clicks. If you want to support basic interaction with the webview, this might be a good approach.

(Overriding -mouseDown: seems to work for WKWebView, it may not work with the legacy WebView. It's a bit of a hack, but you could use an overlay view to catch those events instead.)

like image 131
Jeff Avatar answered Sep 24 '22 11:09

Jeff