Skip to content

Instantly share code, notes, and snippets.

@aduuub
Last active April 3, 2020 02:19
Show Gist options
  • Save aduuub/b0f0e47f15e5eee071f837381851c6c3 to your computer and use it in GitHub Desktop.
Save aduuub/b0f0e47f15e5eee071f837381851c6c3 to your computer and use it in GitHub Desktop.
class BaseViewController: UIViewController {
var loadingView: UIView?
/// Called when the interactive view controller popping gesture is attempted from the right hand side.
/// The view controller should override this if it wants to change its behaviour.
///
/// - Returns: true if you want to prevent the interactive gesture.
func preventInteractivePopGesture() -> Bool {
let isNavBarVisible: Bool = navController?.isNavigationBarHidden == false
let isBackButtonVisible: Bool = self.navigationItem.leftBarButtonItem != nil
let isLoading: Bool = loadingView != nil
if isNavBarVisible && isBackButtonVisible, isLoading == false {
// Allow the user to swipe back
return false
}
// Prevent all other cases unless it is specific to the view controller.
// In which case they can override this method and return a custom result
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment