デバイスの回転
デバイスの回転の検出方法。
viewDidFinishedやinitWithFrameとかで下記を指定。
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
ここでは@selecterでdidRotateが指定してあるので、その名前のファンクションを作成。
- (void) didRotate:(NSNotification *)notification { UIDeviceOrientation orientation = [[notification object] orientation]; if (orientation == UIDeviceOrientationLandscapeLeft){ NSLog(@"Device rotate Leftl!"); } else if (orientation == UIDeviceOrientationLandscapeRight) { NSLog(@"Device rotate Rightl!"); } else if (orientation == UIDeviceOrientationPortraitUpsideDown){ NSLog(@"Device rotate UpsideDownl!"); } else if (orientation == UIDeviceOrientationPortrait) { NSLog(@"Device rotate Portraitl!"); } }
これで回転した場合にdidRotateが呼ばれます。
orientationに現在のデバイスの状況が入るのでそれぞれの状況での処理を書きます。