iOS14 introduced that long-press on back button which opens a callout menu to go back to specific VC in stack.
I would like to disable it, is there a possibility to do such a thing, and if yes how ?
Thanks
iOS14 introduced that long-press on back button which opens a callout menu to go back to specific VC in stack.
I would like to disable it, is there a possibility to do such a thing, and if yes how ?
Thanks
Try to set backButtonDisplayMode to .minimal on your VC ->
if #available(iOS 14.0, *) {
navigationItem.backButtonDisplayMode = .minimal
}
https://developer.apple.com/documentation/uikit/uinavigationitem/3656350-backbuttondisplaymode
It can be done by subclassing UIBarButtonItem. Setting the menu to nil on a UIBarButtonItem doesn't work, but you can override the menu property and prevent setting it in the first place.
class BackBarButtonItem: UIBarButtonItem {
@available(iOS 14.0, *)
override var menu: UIMenu? {
set {
/* Don't set the menu here */
/* super.menu = menu */
}
get {
return super.menu
}
}
}
Then you can configure the back button in your view controller the way you like, but using BackBarButtonItem instead of UIBarButtonItem:
let backButton = BackBarButtonItem(title: "BACK", style: .plain, target: nil, action: nil)
navigationItem.backBarButtonItem = backButton
This is the preferred way because you set the backBarButtonItem only once in your view controller's navigation item, and then whatever view controller it will be pushing, the pushed controller will show the back button automatically on the nav bar. If using leftBarButtonItem instead of backBarButtonItem, you will have to set it on every view controller that will be pushed.