11

これは私の持っているものです: 異なるUIViewControllerを扱うUITabBarController。 UIViewControllerの1つで、デバイスがランドスケープに回転するときに表示されているビューを切り替えようとしています。 重要な部分はiPhoneデバイスを横向きに回転させるときTabBarを非表示にする

は私が正しくメソッド実装されている...風景の中に表示されたビューが画面全体を取る必要があるということです。私の実際に

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 

を私は私の回転が正常に発生していない、と私ビューはスワップしました。 私はステータスバー、ナビゲーションバー、タブバーを隠していますが、タブバーの場所である画面の下部に空白が残っています...

私は、 tabBarは画面全体を見るためには十分ではありません。私は、TabBarControllerやMainWindow内で、 "今はTabBarControllerが必要ない"のようなsomehtingを行うためのいくつかのことがあると思います。しかし、私はこの問題を適切に回避する方法を見ていません。

誰かがこの問題を抱えている場合は、私はいくつかの助けに感謝します。

ありがとう、 サミ。

答えて

33

これは私のために働いた。


- (void)viewDidLoad { 
    [super viewDidLoad];  
    previousRect = self.view.frame; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return YES; 
} 

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration; 
{ 
    if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {  
     [self.navigationController setNavigationBarHidden:TRUE animated:FALSE]; 
     [[UIApplication sharedApplication] setStatusBarHidden:TRUE animated:FALSE]; 
    } 
    else 
    { 
     [self.navigationController setNavigationBarHidden:FALSE animated:FALSE]; 
     [[UIApplication sharedApplication] setStatusBarHidden:FALSE animated:FALSE]; 
    } 
} 

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    UIInterfaceOrientation toOrientation = self.interfaceOrientation; 

    if (self.tabBarController.view.subviews.count >= 2) 
    { 
     UIView *transView = [self.tabBarController.view.subviews objectAtIndex:0]; 
     UIView *tabBar = [self.tabBarController.view.subviews objectAtIndex:1]; 

     if(toOrientation == UIInterfaceOrientationLandscapeLeft || toOrientation == UIInterfaceOrientationLandscapeRight) {     
      transView.frame = CGRectMake(0, 0, 480, 320); 
      tabBar.hidden = TRUE; 
     } 
     else 
     {    
      transView.frame = previousRect;  
      tabBar.hidden = FALSE; 
     } 
    } 
} 

+0

あなたは私の日を過ごしました...実りの男... – Krishnabhadra

+0

+1! –

+0

答えとしてマークしてください... :)それは動作します! ) –

0

このコードは正常に動作しますが、私は、モーダルモードで表示されるのUIViewControllerを閉じたときに、私の見解では20ピクセルで、ステータスバーの下にあります。 私のビューはnavigationcontrollerの中にあるので、私は回転の前にそれを隠さない。

+0

問題はナビゲーションバーに関連しており、IOS 5でのみ発生していることが分かりました。同様の問題が発生した場合は、ナビゲーションバーを非表示にして表示する必要があります。 –

1
  • iOS6用および上記私のために働いた、あまりにもちょうどいくつかの小さな変更を上記の溶液:
  • iOS6での行削除:「previousRect = self.view.frameは、」
  • も置き換える「アニメーション:」 with "withAnimation:"
  • "transView.frame = previousRect;"を下部から削除してください(他の機能では)
  • これは私にとってはこのように機能します。また、ユーザーUBに大きなおかげです。
0

私は、ランドスケープビューでフルスクリーンモードに入るようにタブバーを必要と私はアプローチがこれはハックソリューションであることが判明し、次のような多くの問題を提起し

transView.frame = CGRectMake(0, 0, 480, 320);

を使用して、上記提案してみましたステータスバーを非表示にして再表示します(ポートレート表示を終了した後に再表示されると、ステータスバーと重なることになります)。私はこれをお勧めしません。最終的に完璧に機能したのは、ランドスケープビューを含む新しいView Controllerを作成し、委任を使用して元のVCの機能を再利用することでした。

-1

UITabBarControllerを持っている場合は、その中にUINavigationControllerを入れて、これを行うにはhidesBottomBarWhenPushed(トリッキーなビット)を使うことができます。

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; 

    if (toInterfaceOrientation == UIInterfaceOrientationPortrait) { 
     self.hidesBottomBarWhenPushed = NO; 
     self.navigationController.viewControllers = self.navigationController.viewControllers; 
     [self transitionToGridLayout]; 
    } 
    else { 
     self.hidesBottomBarWhenPushed = YES; 
     self.navigationController.viewControllers = self.navigationController.viewControllers; 
     [self transitionToCoverflowLayout]; 
    } 
} 

トリックはhidesBottomBarWhenPushedフラグがピックアップされるように、あなたのビューコントローラをプッシュすることです。あなたは以下を使うことができます。

self.navigationController.viewControllers = self.navigationController.viewControllers; 
0

このアプローチは、私のために働いている:(のみiOS8でテスト。)

- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 

    UIView *parentView = self.tabBarController.view; 
    CGRect frame = parentView.frame; 
    CGFloat windowHeight = parentView.window.frame.size.height; 

    switch (toInterfaceOrientation) { 
     case UIInterfaceOrientationLandscapeLeft: 
     case UIInterfaceOrientationLandscapeRight: 
      CGFloat tabBarHeight = self.tabBarController.tabBar.frame.size.height; 
      frame.size.height = windowHeight + tabBarHeight; 
      break; 
     default: 
      frame.size.height = windowHeight; 
      break; 
    } 

    [UIView animateWithDuration:duration animations:^{ 
     parentView.frame = frame; 
    }]; 
} 

+0

iPadで動作していませんiOS8 – Borzh

+0

私はこのコードをプロダクションアプリで実行しています。何を見ていますか? iOS 8のどのバージョンですか? – StephenT

+0

iOS 8.2シミュレータを試しました。回転中にタブバーが表示されます。 Btw何がロジック:景観タブバーのフレームの高さがウィンドウの高さによって増加するか? – Borzh

0

サブクラスあなたTabBarControllerを、必要なときにTabBarを隠す:

たぶん
class tabBarVC: UITabBarController { 

    override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) { 
     if size.height < size.width { 
      self.tabBar.hidden = true 
     } else { 
      self.tabBar.hidden = false 
     } 
    } 

} 
0

をあなたはこれを使いたい

- (void)willAnimateRotationToInterfaceOrientation:UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; 

    __block UIView *weakTabBar = [self.tabBarController.view.subviews objectAtIndex:1]; 
    weakTabBar.alpha = 0; 
    [UIView animateWithDuration:duration 
          delay:0 
         options:UIViewAnimationOptionCurveEaseIn // slow at the beggining 
        animations:^{ 
         weakTabBar.alpha = 1; 
        } 
        completion:^(BOOL finished) { 
         weakTabBar.alpha = 1; 
        }]; 
    } 

}

これは、タブバーを非表示にしますが回転アニメーションが滑らかになりません。

関連する問題