EZSwipeController
EZSwipeController copied to clipboard
Breaks "Swipe right to return" functionality
Hi, I'm using navigationController.push(EZSwipeController) to push a new EZSwipeController into navigation stack, but it seems to break iOS's swipe right to return.
That should be disabled somewhere in the code.
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
Place this in your VC which contains your EZSwipeVC and it should work.
I also added the following to prevent the SwipeVC from bouncing horizontally when it is on the first or last page index, not sure if this helps:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
for someview in self.pageViewController.view.subviews {
if someview is UIScrollView {
let scrollview = someview as! UIScrollView
scrollview.delegate = self
}
}
}
extension TaskViewSwipeVC: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if self.currentVCIndex == 0 && (scrollView.contentOffset.x < scrollView.bounds.size.width) {
scrollView.contentOffset = CGPoint(x: scrollView.bounds.size.width, y: 0)
} else if self.currentVCIndex == self.stackVC.count - 1 && (scrollView.contentOffset.x > scrollView.bounds.size.width) {
scrollView.contentOffset = CGPoint(x: scrollView.bounds.size.width, y: 0)
}
}
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
if self.currentVCIndex == 0 && (scrollView.contentOffset.x < scrollView.bounds.size.width) {
scrollView.contentOffset = CGPoint(x: scrollView.bounds.size.width, y: 0)
} else if self.currentVCIndex == self.stackVC.count - 1 && (scrollView.contentOffset.x > scrollView.bounds.size.width) {
scrollView.contentOffset = CGPoint(x: scrollView.bounds.size.width, y: 0)
}
}
}
This solution above works, but there is one more thing you have to do if you are using a UINavigationController. All you have to do is subclass the UINavigationController and use this custom class as your navigation controller.
` class CustomNavigationController: UINavigationController, UIGestureRecognizerDelegate, UINavigationControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self
interactivePopGestureRecognizer?.delegate = self
}
func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
if responds(to: #selector(getter: self.interactivePopGestureRecognizer)) {
if viewControllers.count > 1 {
interactivePopGestureRecognizer?.isEnabled = true
}
else {
interactivePopGestureRecognizer?.isEnabled = false
}
}
}
}
`
Otherwise, you may encounter freezing issues like I did, seen here: https://stackoverflow.com/questions/36503224/ios-app-freezes-on-pushviewcontroller