// 这个方法要在初始进入界面时才会生效,如果在使用的过程中旋转屏幕,依然还是之前的方向
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (orientation == UIInterfaceOrientationLandscapeLeft) {
// Preview
NSLog(@"home 键在左侧 --- ");
self.isHomeKeyLeft = YES;
}
if (orientation == UIInterfaceOrientationLandscapeRight) {
// Preview
NSLog(@"home 键在右侧 --- ");
self.isHomeKeyLeft = NO;
}
// 监听设备方向 旋转才会生效
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
- (void)orientationChange:(NSNotification *)notification {
// NSDictionary* ntfDict = [notification userInfo];
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
switch (orientation)
{
case UIDeviceOrientationPortrait:
break;
case UIDeviceOrientationLandscapeLeft:
NSLog(@"屏幕 left --- home 键在右侧 --- ");
self.isHomeKeyLeft = NO;
break;
case UIDeviceOrientationPortraitUpsideDown:
break;
case UIDeviceOrientationLandscapeRight:
NSLog(@"屏幕 right --- home 键在左侧 --- ");
self.isHomeKeyLeft = YES;
break;
default:
break;
}
}
// 移除通知(旋转时获取屏幕方向)
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIDeviceOrientationDidChangeNotification
object:nil
];