How to Hide Tab Bar Controller ? I want to hide the Tab Bar controller with double tap on UIImageView.
问题:
回答1:
Try this code:
[self.tabBarController.tabBar setHidden:YES];
where tabbarcontroller is needed to be defined...
EDIT
AppDelegateFileName *appDelegate = (AppDelegateFileName *) [[UIApplication sharedApplication] delegate];
[appDelegate.tabbarController.tabBar setHidden:YES];
before doing this make sure that you create a @property declaration of tabbarController
in appDelegate .h file.
回答2:
If using Storyboards you can simply uncheck a checkbox in your ViewController's Attribute Inspector. It's called "Hide Bottom Bar on Push". Very convenient indeed, and no need to handle the showing of the tabBar again after navigating back from your tabBar-less viewController. I don't know in which XCode-version this was introduced, but it's there for XCode 6 + .
回答3:
Use TapGesture Recognizer to detect double taps on a UIIMageview. Then invoke a method on detecting the double double tap. Add the following line of code in that method.
self.tabBarController.tabBar.hidden=YES;
Hope this helps.
回答4:
Use the code below to hide/show tab bar controller in animated style.
hiddenTabBar
is a BOOL
variable.
- (void) hidetabbar {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.0];
for(UIView *view in objtabbar.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
if (hiddenTabBar) {
[view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
}
} else {
if (hiddenTabBar) {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
}
[UIView commitAnimations];
hiddenTabBar = !hiddenTabBar;
}
回答5:
UIViewController has a property
@property(nonatomic, readonly, retain) UITabBarController *tabBarController
which you can set:
self.tabBarController.tabBar.hidden = YES;
回答6:
Swift 2.1:
self.tabBarController!.tabBar.hidden = true
回答7:
Try this when you push the view to the new view:
self.tabbarconroller.tabbar.hidden = YES;
回答8:
Objective-C
[self.tabBarController.tabBar setHidden:YES];
Swift 3
self.tabBarController?.tabBar.isHidden = true
Swift 2
self.tabBarController?.tabBar.hidden = true
回答9:
If you want to change with animation you could use this code:
extension UITabBarController {
func set(visible: Bool, animated: Bool, completion: ((Bool)->Void)? = nil ) {
guard isVisible() != visible else {
completion?(true)
return
}
let offsetY = tabBar.frame.size.height
let duration = (animated ? 0.3 : 0.0)
let beginTransform:CGAffineTransform
let endTransform:CGAffineTransform
if visible {
beginTransform = CGAffineTransform(translationX: 0, y: offsetY)
endTransform = CGAffineTransform.identity
} else {
beginTransform = CGAffineTransform.identity
endTransform = CGAffineTransform(translationX: 0, y: offsetY)
}
tabBar.transform = beginTransform
if visible {
tabBar.isHidden = false
}
UIView.animate(withDuration: duration, animations: {
self.tabBar.transform = endTransform
}, completion: { compete in
completion?(compete)
if !visible {
self.tabBar.isHidden = true
}
})
}
func isVisible() -> Bool {
return !tabBar.isHidden
}
}
More you can read in https://stackoverflow.com/a/50101262/1797194