Reputation: 2268
I have added custom center button in UITabBarViewController, code as below...
self.centerButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.centerButton.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
self.centerButton.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);
[self.centerButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
[self.centerButton setBackgroundImage:highlightImage forState:UIControlStateHighlighted];
CGFloat heightDifference = buttonImage.size.height - self.tabBar.frame.size.height;
if (heightDifference < 0) {
self.centerButton.center = self.tabBar.center;
} else {
CGPoint center = self.tabBar.center;
center.y = center.y - heightDifference/2.0;
self.centerButton.center = center;
}
[self.centerButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.centerButton];
Please check attached screenshot for reference,
Now when I am trying to hide it while moving to other viewcontroller, only tabbar gets hidden and not the center custom button with below code,
[self.tabBarController.tabBar setHidden:YES];
Also tried like this to hide center custom button,
WBTabBarController *objWBTab = [self.storyboard instantiateViewControllerWithIdentifier:ID_CNTRL_TABBAR];
[objWBTab setTabBarHidden:YES];
SetTabBarHidden has been defined as below in WBTabBarController.m,
- (void)setTabBarHidden:(BOOL)tabBarHidden
{
self.centerButton.hidden = tabBarHidden;
self.tabBar.hidden = tabBarHidden;
}
Still no luck, can anybody help me please?
Upvotes: 0
Views: 587
Reputation: 1142
Let try to hide it when view will disappear
-(void) viewWillDisappear:(BOOL)animated{
[self setTabBarHidden:YES];
[super viewWillDisappear:animated];
}
and show it when view will appear
-(void) viewWillAppear:(BOOL)animated{
[self setTabBarHidden:NO];
[super viewWillAppear];
}
Upvotes: 0
Reputation: 11039
Its because you're adding your button as subview to your entire view instead of tabBar's view.
Change [self.view addSubview:self.centerButton];
line with
[self.tabBar addSubview:self.centerButton];
Upvotes: 1
Reputation: 1178
Trying checking Hide Bottom Bar on Push for your ViewController to be opened on storyboard
or you can also use it as this in programmatically approach
self.hidesBottomBarWhenPushed = true
let destinationVC = self.storyboard?.instantiateViewControllerWithIdentifier("StoryBoardID") as! yourVC
self.navigationController?.pushViewController(destinationVC, animated: true)
self.hidesBottomBarWhenPushed = false
Upvotes: 0