Navigationcontroller (navigation Controller) view with a sliding gesture, as long as the left side of the screen drag the page to the right, you can slide back to the previous page. But this feature only slides to the left edge of the screen to trigger, we can slightly change, let it support full-screen sliding back.
1, Full screen slide return realization principle
(1) The system takes the gesture is the Uiscreenedgepangesturerecognizer type object, sees the name to know this is the screen edge sliding gesture. Therefore, the sliding effect of the system itself can only be achieved by side-side sliding.
(2) We add a full-screen slide gesture to the navigation controller ourselves. Then use the newly added sliding gesture to invoke the sliding return function implemented by the system, so that the full-screen sliding function is realized.
(3) Note: We also want to prohibit the system with a sliding gesture, while only the non-root controller has sliding return function, the root controller does not.
2, the effect chart:
3, Implementation code:
Import Uikit
Class Detailviewcontroller:uiviewcontroller, Uigesturerecognizerdelegate {
Override Func Viewdidload () {
Super.viewdidload ()
Let target = Self.navigationcontroller?. interactivepopgesturerecognizer!. Delegate
Let pan = Uipangesturerecognizer (Target:target,
Action:selector ("handlenavigationtransition:"))
Pan.delegate = Self
Self.view.addGestureRecognizer (PAN)
Self.navigationcontroller? interactivepopgesturerecognizer!. Enabled = False
}
Func Gesturerecognizer (Gesturerecognizer:uigesturerecognizer,
Shouldrecognizesimultaneouslywithgesturerecognizer Othergesturerecognizer:
Uigesturerecognizer)-> Bool {
If Self.childViewControllers.count = 1 {
return False
}
return True
}
Override Func didreceivememorywarning () {
Super.didreceivememorywarning ()
}
}
Original from: www.hangge.com