In IOS 7, in addition to the traditional upper-left return key, a gesture that returns to the top-level interface is provided with a right slide. This gesture is supported by the new attribute in Uinavigationcontroller
Interactivepopgesturerecognizer, that is, right-sliding returns only supports switching between Viewcontroller with Uinavigationcontroller as a container and requires some extra work to be used in a custom container.
Basically, control whether the Viewcontroller is enabled for right-sliding return, only this is necessary:
1 self.navigationController.interactivePopGestureRecognizer.enabled = YES;
By default, enabled is yes.
In the actual use, encountered a number of problems, organized as follows:
1. After the custom return button, the right slide returns to fail;
Solution: The more intuitive approach is to use Backbarbuttonitem when customizing the return button:
1 UIButton *backbutton = [UIButton buttonwithtype:uibuttontypecustom];2 //some Initialize code here ... 3 Uibarbuttonitem *baritem = [[Uibarbuttonitem alloc] initwithcustomview:backbutton];4 Self.navigationItem.leftBarButtonItem = Baritem; Not working5 self.navigationItem.backBarButtonItem = Baritem; Serve well
P.S: The difference between Backbarbuttonitem and Leftbarbuttonitem:
http://www.cocoachina.com/ask/questions/show/97110
However, this does not support the case of multiple buttons in the upper left corner. Consider that Interactivepopgesturerecognizer also has the delegate attribute, which replaces the default self . Navigationcontroller. Interactivepopgesturerecognizer.delegate to configure the return of the right slide is also feasible. In the main viewcontroller:
1 self.navigationController.interactivePopGestureRecognizer.delegate = self;
1-(BOOL) Gesturerecognizershouldbegin: (Uigesturerecognizer *) Gesturerecognizer 2 {3 if (Self.navigationcontrol Ler.viewControllers.count = = 1)//Turn off the main interface right slide back 4 {5 return NO; 6 } 7 Else 8 {9 return Yes;10 }11}
The advantage of this is that you can configure all Viewcontroller in the stack in the main viewcontroller to be turned back on, without having to set enabled separately in each viewcontroller.
It is worth noting that after replacing the delegate, you must set a Viewcontroller a in Gesturerecognizershouldbegin: To turn the right slide back, The interactivepopgesturerecognizer.enabled = no is not set at the same time, and the right-slip return is turned on, that is, any of the two is no and the right-slip return is off.
2, the main interface (the first viewcontroller in the Uinavigationcontroller stack) is also turned on by default to return to the right slide. If you are sliding right on the main interface, no action will be taken. But when you want to go to the next level Viewcontroller (such as clicking a line in TableView), the toggle animation does not appear. Cut back to the desktop and then into the application, found directly into the next level Viewcontroller.
Solution: This problem occurs when you initially test the use of the right-side return. In a viewcontroller that uses the custom return button
1 self.navigationController.interactivePopGestureRecognizer.delegate = self;
Resolves problem 1 while causing problem 2. Similar to 1, after replacing the default delegate, Interactivepopgesturerecognizer can invoke the custom return method. The specific reason is unclear, pending the update of "Mark".
3. When you use the right slide back to drag halfway, you will sometimes see three small blue dots lined up on the navigation bar.
Solution: The cause is unclear and the solution is unclear.
P.S: See a method on a post:
1 self.navigationItem.title = @ "";
Can hide the small blue dot, but because the small blue point is not necessary, in the unclear situation is difficult to say whether it is effective.
Posts Link: http://www.tuicool.com/articles/FB3IJ3
Other
(1) In the Project view,self. Navigationcontroller. Interactivepopgesturerecognizer.delegate is actually a
_uinavigationinteractivetransition instances, which are declared as follows:
1 @class Uiscreenedgepangesturerecognizer; 2 3 @interface _uinavigationinteractivetransition: _uinavigationinteractivetransitionbase {4 Uiscreenedgepangesturerecognizer *_edgepanrecognizer; 5} 6 7 @property (readonly) Uiscreenedgepangesturerecognizer * Screenedgepangesturerecognizer; 8 9-(void) _ Configurenavigationgesture;10-(BOOL) _gesturerecognizer: (ID) arg1 Shouldberequiredtofailbygesturerecognizer: (ID) Arg2;11-(void) dealloc;12-(BOOL) Gesturerecognizer: (ID) arg1 Shouldreceivetouch: (ID) arg2;13-(BOOL) Gesturerecogniz ER: (ID) arg1 Shouldrecognizesimultaneouslywithgesturerecognizer: (ID) arg2;14-(BOOL) Gesturerecognizershouldbegin: ( ID) arg1;15-(ID) gesturerecognizerview;16-(ID) Initwithviewcontroller: (ID) arg1 animator: (ID) arg2;17-(ID) screenedg Epangesturerecognizer;18-(void) setnotinteractivetransition;19-(void) startinteractivetransition;20 @end
As you can see, the inside of the delegate, which is actually a uiscreenedgepangesturerecognizer instance in action, is a new class introduced in IOS7 that supports the initialization of switching between viewcontroller in some cases. There are few descriptions of them in Apple's official documentation, as follows:
A UIScreenEdgePanGestureRecognizer looks for panning (dragging) gestures this start near an edge of the. The system uses screen edge gestures in some cases to initiate view controller transitions. You can use this class to replicate the same gesture behavior for your own actions.
After creating a screens edge pan gesture recognizer, assign an appropriate value to the property edges before attaching th E gesture recognizer to your view. Specify from which edges, the gesture may start. This gesture recognizer ignores any touches beyond the first touch.
To support a right-slip return in a custom Viewcontroller container, you might need to use it.
(2) Many applications still use the iOS 6.1 SDK, and a lot of iOS7 users have a very urgent need for right-sliding return, so it is necessary to simulate right-sliding return in iOS 6.1SDK in a short time. Here is a way to achieve the background of uiimage as the next level Viewcontroller by intercepting the parent Viewcontroller interface at push:
Today, I saw the author of a note post, deeply thought is too superficial, here will iOS6 the implementation of sliding back to separate out:
Http://www.cnblogs.com/lexingyu/p/3434340.html
Reference
1, Uiscreenedgepangesturerecognizer Class Reference
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIScreenEdgePanGestureRecognizer_class/ Reference/reference.html#//apple_ref/occ/cl/uiscreenedgepangesturerecognizer
2, _uinavigationinteractivetransition.h
Https://github.com/nst/iOS-Runtime-Headers/blob/master/Frameworks/UIKit.framework/_UINavigationInteractiveTransition.h
3. When customizing the return button, the iOS7 gesture returns problems encountered
Http://www.tuicool.com/articles/FB3IJ3
IOS7 Sliding Back