iOS 6(およびそれ以前のバージョン)では、デバイスが回転しているときにビューコントローラがオフスクリーンになっても、通知は行われません。トップビューコントローラーになると、willAnimateRotationToInterfaceOrientation:duration:
も送られません。
ビューコントローラの現在の向きを追跡し、デバイスの向きをviewWillAppear:
で確認する必要があります。それらが異なる場合は、willAnimateRotationToInterfaceOrientation:duration:
を使用して正しく設定できます。
これは多くのことを行う可能性が高いため、View Controllerが継承する汎用スーパークラスを作成することができます。
典型的な解決策がある:
@implementation MyHandlesOffscreenRotationController
{
BOOL isShowingPortrait;
}
- (void) viewDidLoad
{
[super viewDidLoad];
isShowingPortrait = UIInterfaceOrientationIsPortrait(
[[UIApplication sharedApplication] statusBarOrientation]);
}
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
BOOL currIsPortrait = UIInterfaceOrientationIsPortrait(
[[UIApplication sharedApplication] statusBarOrientation]);
if ((isShowingPortrait && !currIsPortrait) ||
(!isShowingPortrait && currIsPortrait)) {
[self willAnimateRotationToInterfaceOrientation:
[[UIApplication sharedApplication] statusBarOrientation]
duration:0.0f];
}
}
@end
このリンクをご覧ください[http://stackoverflow.com/questions/12650137/how-to-change-the-device-orientation-programmatically-in-ios-6](http://stackoverflow.com/questions/12650137/how-to-change-the-device-orientation-programmatically-in-ios-6) –
このシナリオについては、Appleのドキュメント[here](https://developer.apple.com/library/)を参照してください。 /特派員/ ViewControllerPGforiPhoneOS/RespondingtoDeviceOrientationChanges/RespondingtoDeviceOrientationChanges.html#// apple_ref/doc/uid/TP40007457-CH7-SW13)。 –