0

プログラムでUITabBarを非表示にするにはどうすればよいですか?SOで何度も質問と回答がありましたが、回答にはおおよそ2つの種類があるようです。

1)ナビゲーションコントローラーを使用すると、hidesBottomBarWhenPushedプロパティを使用して、プッシュする前に次のvcのタブバーを非表示にできます。 ここでの典型的な答え

2)タブバーコントローラーのビュー階層をウォークスルーし、タブバーのフレームや可視性を変更します。 ここでの典型的な答え

しかし、どちらの種類の答えも不十分です、imo。1)横向きに回転する場合など、現在のビューでタブバーを非表示にする必要がある場合はどうなりますか。2)Appleライブラリのプライベートビュー階層を介してウェイクアップするコードの半分のページはです。面倒、b。予期せぬ破損を起こしやすい、c。おそらくアプリ承認のブロッカー。

では、アプリは何をするのでしょうか?許可されていないという答えですか?それをサポートするアップルのドキュメント参照はありますか?それは悲しい答えでしょう。イモ、ローテーションケースはタブバーを隠す正当な理由です。

よろしくお願いします。

4

3 に答える 3

1

応答が遅れて申し訳ありませんが、コードを取得しました。デバイスを回転させて、横向きのみのフルスクリーンで「マップ ビュー」を表示する方法を確認できます。

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
    [self hideTabBar:self.tabBarController];
    [self.view bringSubviewToFront:self.eventsMapView];
    self.eventsMapView.bounds = self.view.bounds;
    self.eventsMapView.frame = CGRectMake(0, -208, self.view.frame.size.width, 300);
} else if(toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || toInterfaceOrientation == UIInterfaceOrientationPortrait) {
    [self showTabBar:self.tabBarController];
    [self.view sendSubviewToBack:self.eventsMapView];
}

}

そして、その中でメソッドを呼び出して実際にタブ バーを非表示および表示するため、.m ファイルでもこれらのメソッドを定義する必要があります。

#pragma mark - Tab Bar Methods -

-(void)hideTabBar:(UITabBarController *)tabbarcontroller {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];

    for(UIView *view in tabbarcontroller.view.subviews) {
        if([view isKindOfClass:[UITabBar class]]) {
            [view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
        } else {
            [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
        }
    }

    [UIView commitAnimations];   
}

-(void)showTabBar:(UITabBarController *)tabbarcontroller {       
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];

    for(UIView *view in tabbarcontroller.view.subviews) {
        if([view isKindOfClass:[UITabBar class]]) {
            [view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
        } else {
            [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
        }
    }

    [UIView commitAnimations]; 
}

既に Tab Bar Controller 内にいる場合は、以下のように、すべての子 (または個々のタブ ViewController) が向きに対して TRUE を返すようにする必要があります。

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return TRUE;

}

これがお役に立てば幸いです-質問がある場合はコメントを残してください。回答を更新して、よりよく見せるようにします。

于 2012-08-30T14:38:50.087 に答える
0

ここで便利なコードを見つけることができます。shouldrotate: メソッドから hideTabbar を呼び出すことができます

于 2012-08-29T18:42:58.133 に答える