Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save takasurazeem/319c29192813943328afaf69bd0d5a88 to your computer and use it in GitHub Desktop.
Save takasurazeem/319c29192813943328afaf69bd0d5a88 to your computer and use it in GitHub Desktop.
Popup Navigation Controller
import UIKit
class PopupNavigationController: UINavigationController {
override init(rootViewController: UIViewController) {
super.init(rootViewController: rootViewController)
commonInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}
override init(navigationBarClass: AnyClass?, toolbarClass: AnyClass?) {
super.init(navigationBarClass: navigationBarClass, toolbarClass: toolbarClass)
commonInit()
}
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
commonInit()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
popoverPresentationController?.sourceRect = popoverPresentationController?.sourceView?.bounds ?? .zero
}
private func commonInit() {
modalPresentationStyle = .popover
popoverPresentationController?.delegate = self
popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
}
}
extension PopupNavigationController: UIPopoverPresentationControllerDelegate {
func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
return .none
}
func popoverPresentationController(_ popoverPresentationController: UIPopoverPresentationController, willRepositionPopoverTo rect: UnsafeMutablePointer<CGRect>, in view: AutoreleasingUnsafeMutablePointer<UIView>) {
rect.initialize(to: view.pointee.bounds)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment