A possible way to show the side menu over the status bar is to use a UIWindow with wndowLevel = .statusBar
that will present the status menu UIViewController. Here is a quick implementation I made:
func presentSideMenu() {
let vc = UIViewController() // side menu controller
vc.view.backgroundColor = .red
window = UIWindow()
window?.frame = CGRect(x: -view.bounds.width, y: 0, width: view.bounds.width, height: view.bounds.height)
window?.rootViewController = vc
window?.windowLevel = .statusBar
window?.makeKeyAndVisible()
window?.isHidden = false
window?.addSubview(vc.view)
}
Then you can add a pan recognizer to your view and change the frame of the UIWindow accordingly. Again a simple snippet:
func hideSideMenu() {
window?.isHidden = true
window = nil
}
@objc func pan(recognizer: UIPanGestureRecognizer) {
if recognizer.state == .began {
presentSideMenu()
} else if recognizer.state == .changed {
let location = recognizer.location(in: view)
window?.frame = CGRect(x: -view.frame.width + location.x, y: 0, width: view.frame.width, height: view.frame.height)
} else if recognizer.state == .ended {
hideSideMenu()
}
}
Note that you should hold a strong reference to the UIWindow otherwise it will be released immediately. Maybe you should consider if presenting over the status bar is a good idea though. Hope this helps.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…