解决 RaisedCenterTabBar 在 HidesBottomBarWhenPushed bug

 

   在three20中结合RaisedCenterTabBar发现在ViewController中使用self.hidesBottomBarWhenPushed = YES; 中间那个图片依然显示在中间那个位置没有隐藏。

https://github.com/boctor/idev-recipes/tree/master/RaisedCenterTabBar

 

  结合http://idevrecipes.com/2010/12/16/raised-center-tab-bar-button/ 给到的解决方案,把最后fix的代码贴出来,供大家参考

// Create a custom UIButton and add it to the center of our tab bar
-(void) addCenterButtonWithImage:(UIImage*)buttonImage highlightImage:(UIImage*)highlightImage
{
    button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
    button.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);
    [button setBackgroundImage:buttonImage forState:UIControlStateNormal];
    [button setBackgroundImage:highlightImage forState:UIControlStateHighlighted];
    [button addTarget:self action:@selector(publishClick:) forControlEvents:UIControlEventTouchUpInside];
    
    CGFloat heightDifference = buttonImage.size.height - self.tabBar.frame.size.height;
    if (heightDifference < 0)
        button.center = self.tabBar.center;
    else
    {
        
        CGPoint center = self.tabBar.center;
        center.y = self.tabBar.frame.size.height-buttonImage.size.height/2.0;
        button.center = center;
    }
    
    [self.tabBar addSubview:button];
}
posted @ 2012-06-16 21:21  alex hu  阅读(1711)  评论(2编辑  收藏  举报