Today is the question of hiding tabbar when pushing when tabbar nesting nav.
Before the project also need to do so, at that time iOS7 not out, but also a variety of searching, and then the solution is when the push operation of their own hidden tabbar,push the past, as the back of the time when the pop to display Tabbar, the process of complex also need to write their own animation, The end result is not ideal either.
The first two days of the company app shelves, there was no adaptation to IOS7, XCode4.6 on the development of the compilation and release, incredibly in the iOS7 run up not too big problem, just a nav text dislocation, there is a flash back, but reluctantly still can use, which has a custom tabbar, there are many animations, and later in an introduction iOS7 adaptation of the article to see such a sentence:
Apps that are compiled using the iOS 6 SDK on Xcode 4.6 on iOS
The 7 runtime uses a special simulation mode that tries to save the app's original look. But once you upgrade to Xcode 5, the iOS
Compile on 7SDK and your app will start to appear.
has been written very clearly, so I went to Xcode5 to compile and run the original project, the leak is full, began to collapse completely, a variety of problems surfaced.
Well, back to the point of today's talk, first and everyone to talk about hidesbottombarwhenpushed, from this property name can also know its meaning, the official explanation is this:
If YES, then when this view controller is pushed to a controller hierarchy with a bottom bar (like a tab bar), the Botto M bar would slide out. Default is NO.
The general meaning is that if yes, when the controller is push, the bar at the bottom, such as Tabbar, will slide away, i.e. it will not be displayed on the push view, the default value is No.
The scene I'm talking about is like this:
The outermost is a tabbarcontroller, set up two Navgationcontroller, when one VC push down, the general situation is this:
When you hide the Tabbar, push again, the effect is this:
What, is it true that sometimes this happens? In fact, Apple really considered very thoughtful, for us to create a hidesbottombarwhenpushed this attribute, in order to solve the problem. The code is very simple, a sentence or two words can be, here to score several push situation.
Case1: xib loading or storyboard using identifier to get controller
UIViewController *v2 = [self.storyboard instantiateViewControllerWithIdentifier:@"v2"];v2.hidesBottomBarWhenPushed = YES;[self.navigationController pushViewController:v2 animated:YES];
Case2: Pull, that is storyboard with Performsegue
self.hidesBottomBarWhenPushed = YES;[self performSegueWithIdentifier:@"tov2" sender:nil];self.hidesBottomBarWhenPushed = NO;
TIP: The test proves that this method will only take effect on the next level, continue to push back and will appear tabbar, to continue to push also hide Tabbar also have to use Case3 method, also recommend this!
Case3: Pull, in the Prepareforsegue function
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ [segue.destinationViewController setHidesBottomBarWhenPushed:YES];}
more Convenient : If you are using Storyboard, you can check the properties in the Viewcontroller Settings panel Hide Bottom Bar on Push , and the effect is the same as the above code.
Temporary use of these points, my previous practice, my own manual hiding, stretching view, show not only trouble, compatibility is not good, moved to iOS7 on a lot of problems, but with this property can be very convenient to achieve this demand, and on the iOS6 is also perfectly compatible OH.
Note: There is also a problem, this property only supports non-custom tabbar, that is, only support native Tabbar, if the custom tabbar will produce your unexpected effect, I have encountered before, Because after using hidesbottombarwhenpushed, the system will process the Tabbarcontroller tabbar this view, my previous custom Tabbar practice is that the native Tabbar this view is hidden away, Then add to the tabbar you draw
View, the disadvantage is that your custom Tabbarview receive no response from the system, so I try to customize the Tabbar
View added to the original Tabbar view, that is, do not hide the original Tabbar, but covered in the above, see no difference, the effect can also achieve the effect of the above picture!
The correct usage of ios:hidesbottombarwhenpushed