I have a TabBarController
with three tabs. The first and last tabs are navigation controllers that I want to have swipe back enabled in. The middle tab is just a standard viewController
. By default it seems like swipe back is not enabled. I guess that is because I'm using a back button in these two navigationControllers
. I have tried the following code in the root view controllers of the two navigation controllers to enable it:
In viewDidLoad
:
self.navigationController?.interactivePopGestureRecognizer?.delegate = self
and conforming to the UIGestureRecognizerDelegate
:
func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
if (self.navigationController?.viewControllers.count)! > 1 {
return true
}
return false
}
The swipe back to work now works however occasionally if one of the view controllers pushes another on top the UI and app will all freeze up. What is the correct way to enable and disable swipe back in Swift?
As a side note, to quickly return to default settings without using the ADB command, go to Settings –> System –> Gestures –> System navigation on your device. Tap the gear icon, then adjust the gesture sensitivity slider for the left edge to set things back to normal.
Answer: A: As stated in this article, Switch between apps on iPad - Apple Support. To turn off the multifinger swipe gesture, go to Settings > Home Screen & Dock > Multitasking.
To add a tab, first drag a new View Controller object to the storybard. Next control-drag from the tab bar controller to new view controller and select view controllers under Relationship Segue . Your tab bar controller will update with a new tab.
When the user selects a specific tab, the tab bar controller displays the root view of the corresponding view controller, replacing any previous views. (User taps always display the root view of the tab, regardless of which tab was previously selected. This is true even if the tab was already selected.)
For people like me who find this 2 years later without an answer
ViewController
In viewDidAppear
:
self.navigationController?.interactivePopGestureRecognizer?.delegate = self
and your UIGestureRecognizerDelegate
extension YourViewController: UIGestureRecognizerDelegate {
func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
if gestureRecognizer.isEqual(navigationController?.interactivePopGestureRecognizer) {
navigationController?.popViewController(animated: true)
}
return false
}
Two steps to achieve this:
UIGestureRecognizerDelegate
to your class inheritanceviewDidLoad
add the following:To enable swipe back:
navigationController?.interactivePopGestureRecognizer?.isEnabled = true
To disable swipe back:
navigationController?.interactivePopGestureRecognizer?.isEnabled = false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With