29

アプリに追加の UIWindow を追加しています。メイン ウィンドウは正しく回転しますが、追加したこの追加ウィンドウは回転しません。

現在のデバイスの向きに従って UIWindow を回転させる最良の方法は何ですか?

4

5 に答える 5

45

UIWindow は自分でロールする必要があります。

通知をリッスンしUIApplicationDidChangeStatusBarFrameNotification、ステータス バーが変化したときに変換を設定します。

から現在の向きを読み取り、次の-[UIApplication statusBarOrientation]ように変換を計算できます。

#define DegreesToRadians(degrees) (degrees * M_PI / 180)

- (CGAffineTransform)transformForOrientation:(UIInterfaceOrientation)orientation {

    switch (orientation) {

        case UIInterfaceOrientationLandscapeLeft:
            return CGAffineTransformMakeRotation(-DegreesToRadians(90));

        case UIInterfaceOrientationLandscapeRight:
            return CGAffineTransformMakeRotation(DegreesToRadians(90));

        case UIInterfaceOrientationPortraitUpsideDown:
            return CGAffineTransformMakeRotation(DegreesToRadians(180));

        case UIInterfaceOrientationPortrait:
        default:
            return CGAffineTransformMakeRotation(DegreesToRadians(0));
    }
}

- (void)statusBarDidChangeFrame:(NSNotification *)notification {

    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

    [self setTransform:[self transformForOrientation:orientation]];

}

ウィンドウのサイズによっては、フレームも更新する必要がある場合があります。

于 2011-07-14T18:23:31.550 に答える
1

I don't know that you do anything with the window. But the root controller needs to respond to shouldAutorotate with a YES.

于 2011-07-14T18:13:32.020 に答える