Slide back extension (Global slide back function)

Source: Internet
Author: User

The previous article mentions that the custom navigation bar (Navigationbar) overrides the System return button, causing the sliding function to disappear after a workaround, some friends suggest that sometimes encounter some other requirements, such as to set a full-screen slide back to the function, as the name implies in any position on the screen can be implemented right-sliding back. In fact, if the sliding function to solve the idea and process, this program is not difficult to achieve, or to solve the sliding function disappears easier. First we can solve the following problems: Why does the system gesture not full screen? Then we can print out the gesture properties and analyze it.

Edge is a marginal meaning, it is possible that the system can only control the edge of the sliding back, we can point to further observation. Visible Uiscreenedgepangesturerecognizer is inherited from Uipangesturerecognizer, and edges This property we can also confirm is used to control the edge.     Then we can try to click directly to see if we can directly modify the system to achieve our needs. Visible, it is worth our reference only two, one is none, one is all. The literal meaning can be inferred that none refers to the absence of boundaries, which means that it is impossible to slide.     All the words include the upper and lower left and right four directions, that can slide in any direction, also obviously does not meet our needs. So, that means that we can only create uipangesturerecognizer (the pan gesture substitution below) and add it to the view of the navigation controller, as the navigation controller will be at the bottom and be able to respond to gestures, regardless of the jump.

Let's create a pan gesture and add it ourselves without a system gesture. So, let's just implement the functionality. Before implementing the function, you should be aware of a problem, whether our system already exists sliding back to this function. Since the system gesture has this method, we have also added the gesture to the entire view, then we directly put the return function of the system to use it? Then we'll go back to the original print.

In fact, the first time you print this gesture, the system has already given the target and action, which means that we can directly use, only when the system's target is created, we can directly invoke the system's action method to implement the return function. But there may be a difficulty here, that's us. How to get the target of the system. Because the class cannot be created directly from the method (because the class is private, the Apple does not expose it to us and cannot be used directly). But as we can notice there is also a detail that _uinavigationinteractivetransition and its agent Self.interactivePopGestureRecognizer.delegate are the same type, although not the same object, but we do not care whether they are the same object, because this method is defined in the class. So, we can define a "false" target, so long as it is the same class, we can call the method.

Finally, I will report a warning that cannot find a method, can ignore it, because I have not defined this method, just try to invoke the system to write a good method. This changes the implementation of the function is actually 4 lines of code, here is mainly to provide a thinking process and everyone to share.

Slide back extension (Global slide back function)

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.