これを試してみましょう:最初の内部viewDidLoad
関数はこのコードを使用します:
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
}
次に、2行のコードの通知を受け取る関数を作成します。
- (void)orientationChanged:(NSNotification *)object{
NSLog(@"orientation change");
UIDeviceOrientation deviceOrientation = [[object object] orientation];
if(deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation == UIInterfaceOrientationPortraitUpsideDown){
if(deviceOrientation ==UIInterfaceOrientationPortrait){
NSLog(@"Changed Orientation To Portrait");
// Handle your view.
}
}else{
if(deviceOrientation ==UIInterfaceOrientationLandscapeLeft){
NSLog(@"Changed Orientation To Landscape left");
// Handle your view.
}else{
NSLog(@"Changed Orientation To Landscape right");
// Handle your view.
}
}
}
私の答えがお役に立てば幸いです。乾杯。