iosui-Navigation Controller Full screen slide back effect

Source: Internet
Author: User

The navigation controller comes with a slide-slip function By default, and when the user slides to the left of the interface, there is a slide-off function. But how to achieve full-screen slide return effect?

Analysis:

First Step Analysis:

1. The navigation controller's view comes with a swipe gesture, except that the gesture's trigger range is only on the left.

2. When the user drags on the left side of the interface, it will trigger the swipe gesture method, and has the sliding return function, indicating that the system gesture triggering method has realized the sliding return function.

3. Why is the system gesture triggering method already implemented the sliding return function?

Reason:

    • When you create a sliding gesture object, you need to bind the listener and invoke the target action when the gesture is triggered.

Uipangesturerecognizer *pan = [[Uipangesturerecognizer alloc] Initwithtarget:target action:action];
    • When the user slides to the left of the interface, there is a sliding return function, because the trigger gesture, call the target action method, the action method to implement the sliding return function, otherwise there will be no sliding return effect.

Second Step analysis:

Print navigation controller comes with sliding gestures:

NSLog (@ "%@",self.interactivepopgesturerecognizer);   

Get: <UIScreenEdgePanGestureRecognizer:0x7fe243d29150; state = Possible; Delaystouchesbegan = YES; View = <uilayoutcontainerview 0x7fe243d28d90>; target= < (action=handlenavigationtransition:, Target=<_uinavigationinteractivetransition 0x7fe243d27b30> ) >>

Know:

1. The system comes with gestures that are Uiscreenedgepangesturerecognizer type objects, screen edge swipe gestures

2. System comes with gesture target is an object of type _uinavigationinteractivetransition

The action method called by 3.target is called Handlenavigationtransition:

Uiscreenedgepangesturerecognizer, look at the name to know that the scope of this gesture only in the periphery of the screen, because of this gesture, the system comes with the sliding effect, can only achieve side sliding.

Third Step Analysis:

Now only target, _uinavigationinteractivetransition real type

Through the printing system with the swipe gesture of the agent, found exactly the _uinavigationinteractivetransition object, so it can be guessed that the proxy object is the target object, as long as they get it, the system comes with a sliding gesture target object.

// a proxy object    with a swipe gesture from the print system NSLog (@ "%@", Self.interactivepopgesturerecognizer.  Delegate);

Get:<_uinavigationinteractivetransition:0x7ffabb732cb0>

Implementation code:

Navigation Controller Full Screen swipe note points:

1. Disable the system from using sliding gestures.

2. Only the non-root controller of the navigation controller needs to trigger gestures, use gesture proxies, and control gesture triggering.

- (void) viewdidload{[Super Viewdidload]; //Get system gesturesUiscreenedgepangesturerecognizer *gestu =Self.interactivepopgesturerecognizer; // 获取系统自带滑动手势的target对象
target = self.interactivePopGestureRecognizer.delegate;
//always remember to disable the system gestureself.interactivePopGestureRecognizer.enabled =NO; //add your own full-screen swipe gestureUipangesturerecognizer *pan =[[Uipangesturerecognizer alloc] initwithtarget:target action: @selector (handlenavigationtransition:)]; [Self.view Addgesturerecognizer:pan]; //disable gestures when it is a root controller and open gestures when not a root controller// 设置手势代理,拦截手势触发, When the gesture starts to slide, JudgePan.Delegate=Self ;}#pragmaMark-uigesturerecognizerdelegate//when the gesture starts 作用:拦截手势触发 to slide-(BOOL) Gesturerecognizershouldbegin: (Uigesturerecognizer *) gesturerecognizer{//The number of sub-controllers is only one (this one is the root controller), gesture is not availableBOOL open = self.childViewControllers.count! =1; returnOpen;}

iosui-Navigation Controller Full screen slide back effect

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.