0

タブバーコントローラーを備えたストーリーボードがあります。デバイスが回転したら、別の画面に移動します。つまり、同じレイアウトを横向きに表示するのではなく、まったく異なるものを表示します。

iOS 5では、UITabBarControllerDelegateの次のコードでこれを実現しました

- (BOOL)shouldAutorotateToInterfaceOrientation:      (UIInterfaceOrientation)interfaceOrientation
{
    if(interfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {    
        [self performSegueWithIdentifier: @"toGraph" sender: self];
    }

    return (interfaceOrientation == UIInterfaceOrientationPortrait);

}

iOS 6では、このメソッドは呼び出されなくなりました。私が見ることができるすべての方法は、ビューが回転しているときに処理しますが、デバイスが回転しているときは処理しません。

前もって感謝します。

4

2 に答える 2

2

したがって、実際には、ビューの回転ではなく、デバイスの回転を探す必要がありました。UIDeviceクラスを発見した後、AlternateViewsサンプルコード(ドキュメントオーガナイザーでAlternateViewsを検索するだけ)を使用して、必要なものをすべて取得することができました。

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.delegate = self;

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)
                                                 name:UIDeviceOrientationDidChangeNotification object:nil];

}

- (void)orientationChanged:(NSNotification *)notification
{
    // We must add a delay here, otherwise we'll swap in the new view
    // too quickly and we'll get an animation glitch
    [self performSelector:@selector(showGraphs) withObject:nil afterDelay:0];
}

- (void)showGraphs
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
    {
        [self performSegueWithIdentifier: @"toGraph" sender: self];
        isShowingLandscapeView = YES;
    }

    else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView)
    {
        [self dismissModalViewControllerAnimated:YES];
        isShowingLandscapeView = NO;
    }
}
于 2012-09-29T10:42:25.297 に答える
0

自動回転はiOS6で変更されました。この問題に関するApple開発フォーラムのスレッドは次のとおりです。https://devforums.apple.com/thread/166544?tstart = 30

その他のスレッドは次のとおりです 。http ://www.buzztouch.com/forum/thread.php?tid = 41ED2FC151397D4AD4A5A60&currentPage = 1

https://www.buzztouch.com/forum/thread.php?fid=B35F4D4F5EF6B293A717EB5&tid=B35F4D4F5EF6B293A717EB5

これらからあなたの問題に最も関連する投稿は次のようです:

動作しました...タブ付きアプリの場合、appDelegateの次の行を置き換えました:[self.window addSubview:[self.rootApp.rootTabBarController view]];

これで:[self.window.rootViewController = self.rootApp.rootTabBarController view];

タブなしのアプリを取得するには、次の行を置き換えます。[self.window addSubview:[self.rootApp.rootNavController view]];

これで:[self.window.rootViewController = self.rootApp.rootNavController view];

于 2012-09-29T05:03:29.613 に答える