This article will generally take you to achieve the following functions, nonsense less, first look at things:
What's in the Jpnavigationcontroller.gifq&a:demo? 01. About Customizing the navigation bar
- 01, the first controller's navigation bar is transparent, the second controller's navigation bar is white, the third controller's navigation bar is orange.
So, customize your own navigation bar for each controller.
- 02, support full-screen right slide, this is absolutely necessary. On the full screen right slide, the most detailed, but also the first to explore the problem, I learned that j_ rain, he should be full-screen right-slip originator.
- 03, the most important point, requires full-screen right-slide back when the navigation bar to follow their own controller smooth sliding.
- 04, the following belongs to the updated content, for full-screen right-slide pop gestures to add a sliding start point control API. That is, you can precisely control how long it is right to slide from the left side of the screen, and pop gestures are effective.
- 05, some students and I said that they need to temporarily turn off pop gestures in some interfaces, let me handle it. Now that it's done, you can temporarily turn off the pop gesture and turn it on again when you need it.
02, this new add custom Tabbar
Existing issues
Solution Solutions
01. What did the article say before?
99% of the students who saw my article did not read my previous article, so I need to re-describe the contents of the previous article. But if you want to learn more about the implementation of ideas or need to look back to my article, because this article I speak Tabbar, so Navgationcontroller will not speak very thin.
The previous article was broadly clear, how to adapt to the need to customize the navigation bar for each interface needs.
The following ideas are implemented:
02, navigation bar Update part of the implementation of ideas?
To achieve the goal: 1. Temporarily turn off pop gestures 2. Customizing the right swipe gesture active area
The Interactivepopgesturerecognizer of the system only provides an enabled attribute to us, so if you want to do more things you need to think of other ways. In this case, I chose to customize a uipangesturerecognizer to replace the system's gesture implementation
Custom Pop gestures-(Uipangesturerecognizer *) jp_fullscreenpopgesturerecognizer{if (!_jp_fullscreenpopgesturerecognizer) {_jp_fullscreenpopgesturerecognizer = [Uipangesturerecognizer new]; _jp_fullscreenpopgesturerecognizer. maximumnumberoftouches =1; }return _jp_fullscreenpopgesturerecognizer;} -(void) viewdidload{[Super Viewdidload];Hide the navigation bar completely [Self Setnavigationbarhidden:YES];Adding pop gestures (lazy loading)if (![Self. Interactivepopgesturerecognizer. View. Gesturerecognizers Containsobject:Self. Jp_fullscreenpopgesturerecognizer]) {[Self. Interactivepopgesturerecognizer. View Addgesturerecognizer:Self. Jp_fullscreenpopgesturerecognizer];Replace the system's pops with your own gesturesNsarray *targets = [Self. Interactivepopgesturerecognizer Valueforkey: @ "targets"]; id target = [Targets.firstobject valueforkey:@" target "]; SEL action = nsselectorfromstring (@ " Handlenavigationtransition: "); self.jp_fullscreenpopgesturerecognizer .delegate = [self jp_popgesturerecognizerdelegate]; [self.jp_fullscreenpopgesturerecognizer addTarget:target Action:action]; //system gesture is not available self.enabled = NO;}}
This allows us to use our own gestures instead of the system's right-slide function, so we can customize the right-slip feature in a custom gesture proxy method:
-(BOOL) Gesturerecognizershouldbegin: (Uipangesturerecognizer *) gesturerecognizer{The root controller does not allow popif (Self. Navigationcontroller. viewcontrollers. Count <=1) {ReturnNO; }Pop is not allowed when the user is forbiddenif (!Self. Navigationcontroller. jp_fullscreenpopgestureenabled) {ReturnNO; }Suppresses pop when the point at which the trigger starts is greater than the maximum trigger point specified by the userCgpoint beginninglocation = [Gesturerecognizer locationinview:gesturerecognizer. view];CGFloat maxallowedinitialdistance =Self. Navigationcontroller. Jp_interactivepopmaxallowedinitialdistancetoleftedge;if (maxallowedinitialdistance >=0 && Beginninglocation. x > Maxallowedinitialdistance) {ReturnNO; }Suppress pop when transitioning animations are in progressif ([[Self.navigationcontroller valueforkey:@ "_isTransitioning"] Boolvalue]) {return NO;} //reverse slide prohibit pop cgpoint translation = [Gesturerecognizer Translationinview:gesturerecognizer.view]; if (Translation.x <= 0) {return NO;} //temporarily turn off pop gestures prohibit pop if (self.closepopfortemporary) {return NO;} Span class= "Hljs-keyword" >return yes;}
03, Custom Tabbar?
- Custom Tabbar should meet two points: 1. Slide with the user sliding smoothly 2. You do not need to handle tabbar display and hide in Viewwillappear and viewwilldisappear.
- To meet the above two points, the first thing to consider is that our Tabbar parent control should be who?
- From the above analysis can probably also know that if we add tabbar to the navigation bar, we need to meet the requirements are satisfied.
- To make it easier for everyone to use, I first define a placeholder container view jplinkcontainerview, I add it to the navigation bar, as a child control of the navigation bar, and later, just add your own Tabbar control to the placeholder view.
- When we add the linkage Jplinkcontainerview to the navigation bar, the linkage view goes beyond the scope of the parent control and cannot respond to the Click event. So the first thing we need to do is customize a jpnavigationbar to replace the system's navigation bar. With the help of KVC, we can achieve this.
setValue:navBar forKey:@"navigationBar"];
Now that we have customized the navigation bar, we can overload the HitTest method in Jpnavigationbar, traverse its own child control in this method, and find the Jplinkcontainerview we added. When the clicked Point is on the jplinkcontainerview of the placeholder container view We added, we manually distribute the Click event to our custom Tabbar child control to complete the event delivery of the responder chain.
-(UIView *) HitTest: (Cgpoint) point withevent: (Uievent *) event{Jplinkcontainerview *linkview;for (uiview *subview in self.subviews) {if ([Subview Iskindofclass:[jplinkcontainerview class]] {Linkview = (Jplinkcontainerview *) Subview; break;} } cgpoint viewp = [self convertpoint:point ToView:linkView]; Span class= "Hljs-keyword" >if ([Linkview pointinside:viewp withevent:event]) {// If the clicked point is on the linkage view Linkview, the Linkview responds to the event return [Linkview hittest:viewp withevent:event]; Span class= "Hljs-keyword" >else{return [super hitTest:point Withevent:event]; //otherwise, execute the system default procedure}}
04, use the attention point? 1. About the height of the linkage bottom view
@property(nonatomic)CGFloat jp_linkViewHeight;
Note: If your next interface requires a linkage bottom view, you can pass the value to me immediately after the last controller-(void) pushviewcontroller:animated: Method:
[self.navigationController pushViewController:YourOwnVC animated:YES];YourOwnVC.navigationController.jp_linkViewHeight = YourHopeHeight;
Also note: These two lines of code have a logical relationship, you must first call the push method, Navigationcontroller will alloc, allocate memory address, only the value.
2. About Linkage Bottom view
@property(nonatomic)JPLinkContainerView *jp_linkContainerView;
When you need to add a custom view, just add the custom view to the view.
Note: If you recognize that your current controller is Uitableviewcontroller, if you have a linkage bottom view, you will automatically add a jp_linkviewheight height to the bottom of the extra scrolling area. However, if your controller is adding uitableview on Uiviewcontroller, I will not automatically add the bottom additional scrolling area for you, and you will need to add contentinset for UITableView yourself.
05. What are the knowledge points used in this framework?
- This framework uses a lot of runtime knowledge, including dynamic add properties, dynamic Add methods, Exchange methods, etc., if you are interested in runtime knowledge, welcome to read 1 lines of Code Fast integration button delay processing (hook combat).
- The demo uses a cascading effect like Airbnb's head view, and if you're interested, you can check out my previous article on the TableView Head view cascade effect of Airbnb.
- If you are interested in my previous implementation of a custom navigation bar, click here to customize the navigation bar (setting the navigation bar transparency and color for each interface).
06. Demo Address?
The frame's GitHub address is here [Jpnavigationcontroller]. If my article happens to help you in your actual work, please give a little star, thank you. Even more, if you and I love the Open source, love to share, perhaps a little hand shake, help me forward to more friends to see.
Wen/newpan (author of Jane's book)
Original link: http://www.jianshu.com/p/3ed21414551a
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".
1 lines of code custom "TabBar"-B for each controller