A silky full-screen swipe back gesture

Source: Internet
Author: User

A silky full-screen swipe back gesture full-screen return gesture

Since IOS7, Apple has added support for the right side of the screen to return to interaction, and with Uinavigationcontroller Interactive animations, the operation of Pop to the previous page has been very smooth and silky, and since then, I rarely return using the Back button on the top left navigation bar because it is very unfriendly to one-handed operation, and if an App dares not support sliding back, it is not far away from being unloaded.

Speaking of full-screen return gesture , first I feel that this thing itself may have a problem, after all, a little anti-Apple official interaction, so that users can swipe from anywhere to return this interaction in the domestic App is very common, such as my phone's hand Q, Weibo, NetEase news, public comments, etc. Of course, there are Baidu know--. The product managers here have to praise, from the entire app, whether it is interactive or UI structure and style are very iOS, there is no special wonderful page and interaction, so that the use of UIKit native framework can be very simple to build up, which is also in line with my personal vision of the app: A good app should be simple and elegant , both from the user's point of view and from the code point of view, and call on the product managers to learn more about the app design like this. (You can share how to use Storyboard to quickly build up the UI within an hour)

Fdfullscreenpopgesture

After all, work is work, so it was forced to achieve a pan gesture processing plus and parallax, although in the motion curve, bar processing up and down a lot of effort, but the distance between the system's silky effect is still far away. Over time, after finally being able to support iOS7, we put this issue again to discuss and study, until the micro-blog to see the j_ rain classmate of this article only to find the most simple solution so far. As a result, under his authority, we put this return gesture on the Forkingdog open source, GitHub address, and decisively applied to the Baidu know the app, this is the Demo effect:

After using the system's own edge to return gesture processing functions, all animations and curves are the same as the original effect.
The release of the FDFullscreenPopGesture 1.0 release, and the provision of an AOP form of the API, add it to the project, no code to write, all Uinavigationcontroller to bring this full-screen return effect.

Smooth handling of navigation bar display and hide

Next we find that using the system's Uinavigationbar, the return gesture if the previous page has bar, the next page does not bar, or conversely, the animation is very ugly, give two counter-examples:

Hand Q IOS:

The bar on its personal center page was hidden and then made a fake bar that looked like the rest of the page, but the return gesture started out, and in order to make up, it did the alpha value animation of the next real bar, with two back buttons still overlapping.

Sina Weibo IOS:

The same way as the hand Q, but not the Alpha animation, so it is very obvious.

Why is that? This may be a flaw in the design of the Uinavigationcontroller control API on the navigation bar. A Uinavigationcontroller manages the serial N-Uiviewcontroller stack of push and pop, and Uinavigationbar is managed by Uinavigationcontroller, which leads to the U Iviewcontroller is unable to control its own hidden or displayed bar above. This is very much like the UIApplication global status bar, with a full body, but Apple has the following methods for controlling its status bar for VC after IOS7:

123
(uistatusbarstyle) preferredstatusbarstyle Ns_available_ios((BOOL) Prefersstatusbarhidden NS_ Available_ios(uistatusbaranimation) preferredstatusbarupdateanimation ns_available_ios(7 _0);        

Finally let the global variable become a local variable , although it is hard to write.
But the control of Uinavigationbar is still global, and maybe Apple doesn't think the App should have this weird page structure?

The solution to this problem is not difficult, and the following code is written in the view controller that appears after sliding back:

1234
-(void) Viewwillappear: (BOOL) animated {    [super viewwillappear:animated];    [self. Navigationcontroller Setnavigationbarhidden:YES animated:animated];}     

The system will link transition animations with bar and no bar. But as mentioned above, this is a global variable, but also in all the special page without bar can push and pop pages are processed in reverse, the code is very disorderly. As a result, we try to solve this problem, first look at the effect:

I specifically picked a real bar to fake bar, and then from the false bar to the real bar page, but also pretty silky, transition animation is the system itself.
Ratione materiae FDFullscreenPopGesture Update to version 1.1 and implement our streamlined API, you just have to write a sentence in the bar to hide the View controller:

1234
-(void) viewdidload    [Super viewdidload];    Self . NavigationcontrollerYES;    

Or like the overloaded wording:

123
-(BOOL) Fd_prefersnavigationbarhidden {    YES;} 

Deliberately imitated under the system of the naming style, on this one sentence, the rest will not have to worry about.

About Private APIs

People will question that this uses the UIKit private property and the private API, if the system upgrade has changed? What if the audit is rejected?
First of all, the IOS system SDK for backward compatibility, generally only add methods or modify the method implementation, it is unlikely to directly delete a common method, and the behavior of the private method may indeed change, but the system release frequency is very low, when the new version is released when the original function can work Just fine, big can not worry so far, the SDK is dead person is alive.
The other is the audit problem, in the implementation of Fdfullscreenpopgesture there are two main touches of the private API:

1234
1. Private variable Flag Transition animation is in progress [Self.navigationcontroller valueforkey:@"_istransitioning"];  2. An internal selectornsselectorfromstring (@"handlenavigationtransition:");   

Whether it is KVC or selector reflection, is the use of OBJC runtime to complete, and to this layer, really there is no public private to speak of. Imagine that you are the engineer who developed the Apple Private API Checker tool and gave you an IPA package, how would you check out if there are any private APIs?

First of all, this check must be a static check, it can not be run-time check, because the code logic is so complex, the program to run to see all the Objc_msgsend package does not include the private call this thing is too unrealistic.
To do a static check of the IPA file is definitely to analyze the Mach-o executable file, because at this time a lot of source code level of information has been lost, after analysis can take the following methods:

    • Whether to link the private framework or private symbols in the public framework, this prevents the developer from putting the private header out for the program to call directly.
    • As above, @selector(_private_sel) use -performSelector: the plus method to call the private API directly.
    • Scan all symbols to see if there are inherited selfish classes, overloaded private methods, and method names that have coincident.
    • Scan all string to see if the string constant segment appears and corresponds to the private API.

I think the top three are the most likely to be caught and most likely to be checked out. Again, we use the method of string KVC and reflection selector, should belong to the last, this time it is difficult to choose, take it handleNavigationTransition: , it seems harmless ah, my own class inside the method can also name this, so simply by the string hit the private API decision, Apple can easily fire a big bunch of developers.
In summary, I think the use of the method of using a string of private API is relatively safe, our APP will be submitted for review, if a few days you can still read this text, that my guess is wood wrong, we can rest assured that use.

0 Demo of code

Another interesting thing is that our demo project on GitHub has written a line of code that achieves the following effect:

The project looks like this, and the view controller class is not written, in order to embody FDFullscreenPopGesture the AOP nature:

The page is built by Storyboard:

The properties of the control page Hide bar can also be invoked with Runtime Attributes:

This completes a very clean Demo.

Add to your project

First request minimum support iOS7, I think at the end of WWDC 2015, after iOS9 release, the mainstream App will iOS7 jump.
is still familiar with the Cocoapods installation:

1
' ~> 1.1 '

If you don't find it pod setup .

Advertising time

My side is recruiting IOS, coordinates Beijing, hope to find a code specification, love with IB, lazy to write duplicate code, do not love overtime classmate, I believe there is a lot of space for you to learn and upgrade, you can also participate in the Forkingdog Open source group to do something dick, welcome to private chat or resume to the [ Email protected]

2


Original article, reprint please specify the original address: blog.sunnyxx.com

A silky full-screen swipe back 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.