9

Tito のコード スニペットを使用して、タブ バーにカスタム ボタンを追加しています: https://github.com/tciuro/CustomTabBar

(UITabbarController をサブクラス化し、カスタム ボタンを追加する

// .. created a UIButton *button
[self.view addSubview:button];

)

これは、「プッシュ時にボトムバーを非表示にする」オプションが有効になっているナビゲーションコントローラー内のサブビューの場合を除いて、ストーリーボードベースのアプリでうまく機能します。これにより、約束どおりタブ バーが非表示になりますが、カスタム ボタンは非表示になりません。タブバー自体にサブビューとしてボタンを追加する必要があるようですか? ボタンを表示さえしなかったこの醜いコードを試しました:

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

何か案は?

更新: 私の解決策: 私の 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;
                     }
                     completion:^(BOOL finished){
                     }];
    }
}

タブバーと調和した滑らかな効果を得るために、アニメーションの持続時間を 0.35 秒に設定する必要がありました。

4

4 に答える 4

3

ボタンをタブバーの一部にしてみませんか。

tabBarController.tabBar.addSubView(yourButton)

すべてが解決するでしょう。乾杯!

于 2016-10-20T01:21:20.283 に答える
1

One easy way to handle this would be to create an instance of the button in .h of your file.

UIButton *customTabButton;

When calling the hides bottom bar on push set the button property to hidden and reset it again in the other views if the bottom bar is visible.

    shareFbButton.hidden=YES;

You can check this is the viewDidLoad of all the files and put this line of code if needed to make sure you are displaying the button and hiding the button on all the pages you need.

 if(self.tabBarController.tabBar.isHidden){

 // set or reset the custom button visibility here 
}

This is one way.

于 2012-08-16T19:54:53.313 に答える
0

これには2つの方法があると思います。

1)古いトップビューコントローラーとタブバーの上にあるビューにボタンを取得しようとしますが、プッシュされた新しいトップビューコントローラーの下にあります。

2)新しいView Controllerが押されたときにボタンをアニメーション化します。

1 つ目は、文書化されておらず、サポートされておらず、いつでも変更される可能性がある iOS 独自のビュー階層をいじる必要があります。

2 つ目は、ユーザーが気付かない程度にアニメーションを滑らかに見せることです。それは完全に完璧に振る舞うという問題ではなく、適切に見えるだけです。

個人的には、ボタンが消えるアニメーション (アルファを 0 にアニメートする) と、タブ バーを超えるビュー コントローラーが表示されるかどうかに基づいて再表示されることをお勧めします。

ナビゲーションのアニメーションは (私は信じています) 0.3 秒です。ボタンがタブ バーの中央にある場合、ビュー コントローラーでのアニメーションがボタンに到達すると (それよりも早くない場合)、ボタンを非表示にする可能性が高くなります。

これにより、ボタンがタブ バーとまったく同じように動作するわけではありませんが、トランジションの速度が非常に短いため、ユーザーにはまったく気付かれません。

ここで、自分自身に尋ねる質問を提供します。タブ バーにオーバーラップするビュー コントローラーをプッシュする必要があるのはなぜですか? モーダルView Controllerを提示するよりも、それが望ましい/必要なのはなぜですか? 強く主張できる場合は、頑張ってください。ただし、必要がない場合は、モーダル ビュー コントローラーで必要なエクスペリエンスを実現できる可能性があります。

于 2012-08-20T22:44:32.850 に答える
0

にボタンを配置するには、これをチェックしますUITabBar。で動作するかどうかを確認してくださいhidesBottoBarWhenPushed

于 2012-06-27T12:08:07.993 に答える