Enjoy the silky ~ Full Screen sliding return gesture ~ Get in, gesture get

Source: Internet
Author: User

Enjoy the silky ~ Full Screen sliding return gesture ~ Get in, gesture get
Full Screen response gesture

After iOS7, Apple addedRight-click the screen edge and returnInteractive support, combined with the Interactive Animation of UINavigationController, the pop-to-Previous Page operations become very smooth and silky. From then on, I rarely click the return button in the navigation bar in the upper left corner to return a result, because it is unfriendly to single-handed operations. If an App dares not to slide back, it is not far from being detached.

SpeakingFull Screen response gestureFirst of all, I think this may be a problem. After all, it is a bit opposite to Apple's official interaction, so that users can slide and return from any place. This interaction is very common in domestic apps, for example, Q, Weibo, Netease news, and public comments on my mobile phone, and Baidu knows --. The right product managers have to give a thumbs up. From the perspective of the entire App, there is no really amazing page or interaction, whether it is interaction or the iOS structure and style, so that the use of the native framework of UIKit can be easily set up, which is also in line with my personal vision for the App:A good App should be simple and elegant from the user's point of view or from the code point of view., Called on various product managers to learn more from such a true App design. (In the future, we will share how to use Storyboard to quickly build the UI within one hour)

Fdfullscreenpopgsture

After all, work is a task, so it is forced to implement a set of pan gestures to process the addition and parallax. Although it has worked a lot on the Motion Curve and bar processing, however, it is still far from the system's silky effect. Over time, after we finally had the lowest support for iOS7, we took this issue for further discussion and research until we saw it on Weibo.J _ rainAfter this article, I found the simplest solution so far. With his authorization, we opened the open-source response gesture on forkingdog and applied it to Baidu zhiapp. This is a Demo:

After using the system's own edge return gesture processing function, all animations and curves are the same as native effects.
So it was released.FDFullscreenPopGestureVersion 1.0 provides an API in the AOP form and adds it to the project without writing any code. All UINavigationController comes with this full screen response.

Display and hide of the silky processing navigation bar

Next we will find that when we use the UINavigationBar of the system, if there is a bar on the previous page in the returned gesture, or if there is no bar on the next page, or in turn, the animation will be very ugly. Let's look at two examples:

Q iOS:

The bar on its personal Center page is hidden, and a fake bar similar to other pages is made, but the returned gesture shows the stuffing at the beginning. To make up for it, we also made an alpha animation for the real bar, and the two return buttons overlap.

Sina Weibo iOS:

The implementation method is the same as that of Q, but the alpha animation is not done, so it is very obvious.

Why? This may be the design defect of UINavigationController in controlling APIs in the navigation bar. A UINavigationController manages the serial push and pop of N UIViewController stacks, while UINavigationBar is managed by UINavigationController, which makes the UIViewController unable to control the bar on its own to hide or display it separately. This is very similar to the Global status bar of the UIApplication, and the whole body has to be moved. However, Apple provides the following methods for vc to control its status bar after iOS7:

123
- (UIStatusBarStyle)preferredStatusBarStyle NS_AVAILABLE_IOS(7_0);- (BOOL)prefersStatusBarHidden NS_AVAILABLE_IOS(7_0);- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation NS_AVAILABLE_IOS(7_0);

Finally let thisGlobal VariablesChangedLocal variableAlthough it is hard to write.
However, the UINavigationBar control is still global. Maybe Apple doesn't think the App should have such a strange Page Structure?

It is not difficult to solve this problem. Write the following code in the view controller that appears after sliding:

1234
- (void)viewWillAppear:(BOOL)animated {    [super viewWillAppear:animated];    [self.navigationController setNavigationBarHidden:YES animated:animated];}

The system will link the transition animation with and without bar. However, as mentioned above, this is a global variable. We have to reverse process all the pages that can be pushed and pop on the special pages without bar. The code is very messy. Therefore, we tried to solve this problem first. Let's look at the effect first:

I specifically picked a page from the real bar to the fake bar, and then from the fake bar to the real bar. It's pretty smooth, and the transition animation is all done by the system itself.
Just putFDFullscreenPopGestureUpdate to version 1.1 to implement our simplified API. You only need to write a sentence in the view controller to be hidden in bar:

1234
- (void)viewDidLoad    [super viewDidLoad];    self.navigationController.fd_prefersNavigationBarHidden = YES;}

Or you may like to rewrite the statement as follows:

123
- (BOOL)fd_prefersNavigationBarHidden {    return YES;}

Deliberately imitating the naming style of the system, you don't have to worry about the rest.

Private APIs

You may question whether the private attributes and private APIs of UIKit are used. What should I do if the system upgrade changes? What if the review is rejected?
First, for backward compatibility, the iOS SDK generally only adds methods or modifies method implementations, and is unlikely to directly delete a common method. The behavior of private methods may indeed change, however, the system release frequency is very low after all. When a new version is released, check whether the original function can work. You don't have to worry about this far. The SDK is a dead person.
Another issue is review. fdfullscreenpopgsture has two major implementations that touch private APIs:

1234
// 1. private variable flag whether the transition animation is in progress [self. navigationController valueForKey: @ "_ isTransitioning"]; // 2. an internal selectorNSSelectorFromString (@ "handleNavigationTransition :");

Both kvc and selector reflection are completed using objc runtime. At this layer, there is really no public private. Imagine that you are the engineer who developed the Apple private API check tool and gave you an ipa package. How do you check whether there is a private API in it?

First, this check must be a static check. It cannot be a runtime check because the code logic is so complex, it is unrealistic to run the program to see that all objc_msgSend packages do not include private calls.
If you perform static checks on the ipa file, you must analyze the Mach-O executable file. Because a lot of source code-level information is lost, the following methods can be taken after analysis:

  • Whether the private symbols in the private framework or public framework are linked. This prevents developers from dumping all private headers for direct calls by the program.
  • Same as above, use@selector(_private_sel)Add-performSelector:To directly call private APIs.
  • Scan all the symbols to see if there are classes inherited from selfish, private methods reloaded, and method names that overlap.
  • Scan allStringTo check whether the String constant segment corresponds to the private API.

I think the first three articles are most likely to be caught and most likely to be checked out. Let's take a look at the method kvc and reflection selector that we use strings. It should belong to the last one. At this time, it is difficult to choose.handleNavigationTransition:For example, it seems that humans and animals are harmless. The methods in my own class may also name this, So Apple can easily mistakenly hurt a large number of developers simply by hitting the private API in the string.
In summary, I think it is relatively safe to use private APIs using strings. Our App will be submitted for review immediately. If you can read this text in a few days, my guess is wrong. You can use it with confidence.

Demo of code 0

Another interesting thing is that we have written a line of code in the demo project on github to achieve the following results:

The project looks like this, and the view controller class is not written either.FDFullscreenPopGestureThe AOP nature:

The page is built by Storyboard:

The property that controls the hidden bar on the page can also be simulated using Runtime Attributes:

This completes a very clean Demo.

Add to your project

First, we need to support iOS7 at the lowest level. I want to end with WWDC 2015. After iOS9 is released, mainstream apps will jump to iOS7.
Still familiar with cocoapods installation:

1
pod 'FDFullscreenPopGesture', '~> 1.1'

If it is not foundpod setup.

 

Thanks to Sunnyxx, it has been integrated into the existing project. It is very useful !!!! Original post address: http://blog.sunnyxx.com/2015/06/07/fullscreen-pop-gesture/

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.