I have a custom "header" in my app, with an hidden titlebar.
How do I set the header (a simple UIView) as the handle zone to move the window?
I have a custom "header" in my app, with an hidden titlebar.
How do I set the header (a simple UIView) as the handle zone to move the window?
In my case, I had a custom UINavigationController and I needed to override touchesBegan but it should be easy to adopt the following code in your case.
We get the NSWindow object which is not directly available in Mac Catalyst and then perform the drag event when our navbar receives a touch. You can use this on any other view, it doesn't need to be an UINavigation item.
public extension UIResponder {
func performMacCatalystWindowDrag() {
#if targetEnvironment(macCatalyst)
guard let nsApp = ((NSClassFromString("NSApplication") as? NSObject.Type)?.value(forKey: "sharedApplication") as? NSObject),
let currentEvent = nsApp.value(forKey: "currentEvent") as? NSObject,
let nsWindow = currentEvent.value(forKey: "window") as? NSObject else { return }
nsWindow.perform(NSSelectorFromString("performWindowDragWithEvent:"), with: currentEvent)
#endif
}
}
And in your custom navigation bar override touchesBegan
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
performMacCatalystWindowDrag()
super.touchesBegan(touches, with: event)
}
The above code doesn't belong to me, click here to see more.