アプリに追加の UIWindow を追加しています。メイン ウィンドウは正しく回転しますが、追加したこの追加ウィンドウは回転しません。
現在のデバイスの向きに従って UIWindow を回転させる最良の方法は何ですか?
アプリに追加の UIWindow を追加しています。メイン ウィンドウは正しく回転しますが、追加したこの追加ウィンドウは回転しません。
現在のデバイスの向きに従って UIWindow を回転させる最良の方法は何ですか?
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]];
}
ウィンドウのサイズによっては、フレームも更新する必要がある場合があります。
I don't know that you do anything with the window. But the root controller needs to respond to shouldAutorotate with a YES.