でinfo.plist
、サポートされている唯一の方向を に設定しPortrait
ます。次に、viewDidLoad
メソッドに次を追加します。
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
これにより、メソッドが呼び出されます。
- (void)didRotate:(NSNotification *)aNotification; {
UIDeviceOrientation currentDeviceOrientation = [[UIDevice currentDevice] orientation];
switch(currentDeviceOrientation){
case UIDeviceOrientationPortrait:
break;
case UIDeviceOrientationPortraitUpsideDown:
break;
case UIDeviceOrientationLandscapeLeft:
break;
case UIDeviceOrientationLandscapeRight:
break;
default:
break;
}
}
そこから、任意のオプションに基づいて、好きなことを行うことができます。また、これを追加することを忘れないでください:
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
あなたにメソッドを解放します。それが役立つことを願っています!