[[UIDevice currentDevice]beginGeneratingDeviceOrientationNotifications];? ? //建立通知中心
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
-(void)orientationChanged:(NSNotification *)notification{
UIDeviceOrientation orientation=[[UIDevice currentDevice]orientation];
switch (orientation) {
case UIDeviceOrientationFaceUp:
NSLog(@"設(shè)備正面朝上");
break;
case UIDeviceOrientationFaceDown:
NSLog(@"設(shè)備正面朝下");
break;
case UIDeviceOrientationPortrait:
NSLog(@"設(shè)備處于正常朝向,主屏幕按鈕在下方");
break;
case UIDeviceOrientationPortraitUpsideDown:
NSLog(@"設(shè)備處于縱向,主屏幕按鈕在上方");
break;
case UIDeviceOrientationLandscapeLeft:
NSLog(@"設(shè)備側(cè)立,左邊朝下");
break;
case UIDeviceOrientationLandscapeRight:
NSLog(@"設(shè)備側(cè)立,右邊朝下");
break;
default:
break;
}
}