Swift Navigation Controller (navigationcontroller) Full screen sliding return function implementation

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.