小编bjo*_*ern的帖子

当hidesBottomBarWhenPushed为"TRUE"时,如何隐藏自定义标签栏按钮

我正在使用Tito的代码片段向我的标签栏添加自定义按钮:https: //github.com/tciuro/CustomTabBar

(对UITabbarController进行子类化并使用添加自定义按钮

// .. created a UIButton *button
[self.view addSubview:button];
Run Code Online (Sandbox Code Playgroud)

)

这适用于我的基于故事板的应用程序,除了导航控制器中的子视图的情况,启用了"隐藏推杆底部栏"选项.这会按照承诺隐藏标签栏,但不会隐藏自定义按钮.似乎按钮应作为子视图添加到标签栏本身?我尝试了这个丑陋的代码甚至没有显示按钮:

for(UIView *view in self.view.subviews)
{
    if([view isKindOfClass:[UITabBar class]])
    {
        [view addSubview:button];
        break;
    }
}
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

更新: 我的解决方案:在我的ApplicationDelegate中,我定义了以下方法,我在viewWillAppear或viewWillDisappear方法中随时调用这些方法:

-(void)hideCenterButton:(BOOL)animated
{
    if(animated){

    [UIView animateWithDuration:0.3
                          delay:0.0f
                        options:UIViewAnimationCurveLinear
                     animations:^{
                         CGRect frame = self.centerButton.frame;
                         frame.origin.x = -100;
                         self.centerButton.frame = frame;
                     }
                     completion:^(BOOL finished){
                     }];
    }
}

-(void)showCenterButton:(BOOL)animated
{
    if(animated){

    [UIView animateWithDuration:0.35
                          delay:0.0f
                        options:UIViewAnimationCurveLinear
                     animations:^{
                         CGRect frame = self.centerButton.frame;
                         frame.origin.x = (self.view.superview.frame.size.width / 2) - (self.centerButton.frame.size.width / 2);
                         self.centerButton.frame = frame; …
Run Code Online (Sandbox Code Playgroud)

uitabbarcontroller ios ios5

9
推荐指数
1
解决办法
3545
查看次数

标签 统计

ios ×1

ios5 ×1

uitabbarcontroller ×1