I'm following the example on how to create a tab bar with a center button like Path,Instagram, etc from here: http://idevrecipes.com/2010/12/16/raised-center-tab-bar-button/
The problem I have is that when a view is pushed onto the stack that sets HidesBottomBarWhenPushed to hide the tab bar, the center button is still displayed.
In the comments, several other people have had this problem, but there's no working solution. (I've tried all the suggested solutions in the comments)
I came up with a hacky solution-- store a reference to the center button in an unrelated singleton class, and then have the pushed view hide the button when it is loaded, and unhide it when it dissapears-- but this just feels wrong, and it looks funny because you can see the button dissapear before the push view animation starts.
Has anyone got this working?
I had the same problem. I edited the BaseViewController.m (my UITabBarController subclass) by overriding the following viewDidLayoutSubviews method (button is my center button) as followed.
- (void)viewDidLayoutSubviews{
button.center = self.tabBar.center;
}
Now your button follows the tabbar.
You have to do this same but with UIImageView and add it to tabBar:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController: (UIViewController *)viewController
{
if (tabBarController.selectedIndex != AUCenterTabBarButtonIntex) {
self.centerImageView.highlighted = NO;
} else {
self.centerImageView.highlighted = YES;
self.selectedIndex = AUCenterTabBarButtonIntex;
}
}
- (void)addCenterImageViewWithImage:(UIImage *)image highlitedImage:(UIImage *)highlitedImage
{
UIImageView *centerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, image.size.width/2, image.size.height/2)];
centerImageView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
centerImageView.image = image;
centerImageView.highlightedImage = highlitedImage;
CGFloat heightDifference = centerImageView.frame.size.height - self.tabBar.frame.size.height;
if (heightDifference < 0)
centerImageView.center = CGPointMake(self.tabBar.center.x, centerImageView.center.y);
else
{
CGPoint center = self.tabBar.center;
center.y = (self.tabBar.frame.size.height/2) - (heightDifference/2);
centerImageView.center = center;
}
[self.tabBar addSubview:centerImageView];
self.centerImageView = centerImageView;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With