私は最近同じ問題に対処しなければなりませんでした。私の解決策は次のとおりです。
回転できるようにしたいビューのUIViewController内に、通知ハンドラーを追加しますUIDeviceOrientationDidChangeNotification
-(void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotateFromInterfaceOrientation)
name:@"UIDeviceOrientationDidChangeNotification" object:nil];
}
didRotateFromInterfaceOrientation
もちろん、メソッドを実装する必要があります。
そのメソッド内で、現在の向きを取得できます
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
次に行ったのは、向きに基づいて、表示したいビューを評価することでした
switch (orientation) {
case UIDeviceOrientationLandscapeLeft:
NSLog(@"UIDeviceOrientationLandscapeLeft");
[self presentModalViewController:LandscapeView animated:YES];
break;
case UIDeviceOrientationLandscapeRight:
NSLog(@"UIDeviceOrientationLandscapeRight");
[self presentModalViewController:LandscapeView animated:YES];
break;
case UIDeviceOrientationPortraitUpsideDown:
NSLog(@"UIDeviceOrientationPortraitUpsideDown");
[LandScapeview dismissModalViewControllerAnimated:YES];
break;
case UIDeviceOrientationPortrait:
NSLog(@"UIDeviceOrientationPortrait");
[LandscapeView dismissModalViewControllerAnimated:YES];
break;
case UIDeviceOrientationFaceUp:
NSLog(@"UIDeviceOrientationFaceUp");
break;
case UIDeviceOrientationFaceDown:
NSLog(@"UIDeviceOrientationFaceDown");
break;
default:
break;
}
}
少しでもお役に立てれば幸いです。