A silky full-screen swipe back gesture
Reprinted from Http://www.cocoachina.com/ios/20150610/12076.html
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.
As a result, Fdfullscreenpopgesture 1.0 was released, and an AOP form of API was added to the project, where no code was written, and all Uinavigationcontroller brought the full screen back.
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:
-(Uistatusbarstyle) Preferredstatusbarstyle Ns_available_ios (7_0);-(BOOL) Prefersstatusbarhidden NS_AVAILABLE_IOS ( 7_0);-(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:
-(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 updated the fdfullscreenpopgesture to version 1.1 and implemented our streamlined API, you just have to write a sentence in the bar to hide the View controller:
-(void) viewdidload [Super Viewdidload]; Self.navigationController.fd_prefersNavigationBarHidden = YES;}
Or like the overloaded wording:
-(BOOL) Fd_prefersnavigationbarhidden {return 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:
1. The private variable flag transition whether the 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, use @selector (_private_sel) plus-performselector: 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 handlenavigationtransition: It seems harmless ah, my own class inside the method can also be named this come, So by simply hitting the private API with a string, Apple can easily hit a 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 the AOP nature of Fdfullscreenpopgesture:
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:
Pod ' fdfullscreenpopgesture ', ' ~> 1.1 '
If you don't find it, pod setup.
A silky full-screen swipe back gesture