IOS 7 Slide back to those things

Source: Internet
Author: User

Original address: http://weizhe.me/ios-7-back-gesture-sample/

With the increasing popularity of smartphones, the larger the screen, the sliding back gesture has become the standard feature of an application, and it can even be said that not sliding back is an interactive experience of the human race.

Sliding back now roughly has the following 3 types: Using the Uiswipegesturerecognizer implementation, the effect for the user in the screen to the right to swipe the finger, the page returned. Using the Uipangesturerecognizer implementation, the effect for the user on the screen to the right slide the finger, release the page back. Using the sliding return implementation provided by IOS 7, the effect is that the user's finger enters the screen from left to right from outside the screen, and the page returns after the release.

The first two implementations are a common practice before IOS 7 is launched, and now it's outdated and poorly experienced, with a third, personal recommendation, with the following advantages: Good interaction and animation effect system-level support, easy to implement, code clarity does not conflict with some of the on-screen gestures

Although the advantages are obvious, but in the use of the process, there will be some problems worth our attention, then we will be one by one to solve them. 1. How to set the custom return button picture.

If our return button doesn't need to display text, or the displayed text is fixed and can be done in the picture, then I recommend the return button by setting up the new IOS 7 introduced backindicatorimage. The code is as follows:

1 2 3 UIImage *image = [uiimage imagenamed: @ "nav_back_btn"]; [Uinavigationbar appearance]. Backindicatorimage = image; [Uinavigationbar appearance]. Backindicatortransitionmaskimage = image;

This setting will find that the picture is rendered into a navigationbar tintcolor color, how to show the original picture color. You also need to use a new attribute Renderingmode for UIImage in IOS 7. We need to generate a picture of Renderingmode as Uiimagerenderingmodealwaysoriginal, let's add this line of code:

1 2 3 4 UIImage *image = [uiimage imagenamed: @ "nav_back_btn"]; image = [Image imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]; [Uinavigationbar appearance]. Backindicatorimage = image; [Uinavigationbar appearance]. Backindicatortransitionmaskimage = image;

So that our picture will be able to show the original color. 2. Use the UIButton to customize the return button, how to use the sliding back of the system.

When we need to display different text on the return button, we can't use backindicatorimage, we want to customize a UIButton to generate Uibarbuttonitem, and then set the Navigationbar Leftbarbuttonitem. If the Leftbarbuttonitem is set, the sliding return of the system will fail. We need to add this line of code to the Uiviewcontroller.

1 Self. Navigationcontroller. Interactivepopgesturerecognizer. delegate = self;

Run up a look, uh ... can slide back in. 3. How to make sliding return as easy as the default effect of triggering.

Play for a while you find that there seems to be something wrong, how not as easy as before triggered.

Yes, when the navigationController.interactivePopGestureRecognizer.delegate is set, although sliding back to restore, but it is a bit "disabled", the specific performance of two points:

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.