11

だからここに私が持っているものがあります:異なるUIViewControllersを処理するUITabBarController。UIViewController の 1 つで、デバイスが横向きに回転したときに表示されるビューを切り替えようとしています。重要な部分は、横向きに表示されるビューは画面全体を占める必要があるということです...

メソッドを正しく実装しました:

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

実際、回転が正しく行われており、ビューがスワップされています。ステータスバー、ナビゲーションバー、タブバーも非表示にしますが、画面の下部にタブバーの場所である空白スペースが残っています...

したがって、画面全体にビューを表示するには、tabBar の隠しプロパティを設定するだけでは不十分であると想定しています。TabBarController または MainWindow 内で、「今は TabBarController は必要ありません」のようなことを言う必要があると思います。しかし、この問題を適切に回避する方法がわかりません。

誰かがこの問題を回避している場合は、助けていただければ幸いです。

ありがとう、サミ。

4

8 に答える 8

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;
        }
    }
}

于 2009-10-12T13:37:26.413 に答える
1
  • 上記の解決策は、iOS6以降でいくつかの小さな変更を加えただけでも機能しました。
  • iOS6 では次の行を削除します: " previousRect = self.view.frame; "
  • また、「 animation: 」を「 withAnimation: 」に置き換えます
  • 「transView.frame = previousRect;」を下部から削除します(else関数内)
  • このように私にとってはうまくいきます。そして、ユーザー UB に感謝します。
于 2012-11-19T23:10:03.930 に答える
0

横向きでフルスクリーンモードにするにはタブバーが必要で、上記のアプローチを使用してみました

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

これはハッキーな解決策であることが判明し、ステータスバーの非表示と再表示など、多くの問題が発生しました(ポートレートビューを終了した後に再表示すると、ビューがステータスバーと重なる)。私はこれをお勧めしません。最終的に私にとって完璧に機能したのは、ランドスケープビューを含む新しいビューコントローラーをプッシュし、委任を使用して元のVCの機能を再利用することでした。

于 2012-11-23T05:32:26.593 に答える
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;
                     }];
    }

}

これはタブ バーを隠しませんが、回転アニメーションをよりスムーズにします。

于 2015-04-24T19:25:44.870 に答える
0

このアプローチは私のために働いています:

- (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;
    }];
}

(iOS8 でのみテストされています。)

于 2014-11-30T18:49:00.570 に答える
0

このコードは正常に動作しますが、モーダルに表示される uiviewcontroller を閉じると、ビューがステータス バーの下に 20 ピクセル表示されます。私のビューはナビゲーションコントローラーの中にあるので、回転する前に非表示にしません。

于 2012-05-08T15:16:04.710 に答える
-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フラグが選択されるようにView Controllerをプッシュすることです。以下を使用できます。

self.navigationController.viewControllers = self.navigationController.viewControllers;
于 2013-07-03T16:14:52.703 に答える