您的位置:首页 > 移动开发 > IOS开发

ios开发-判断手机方向改变

2014-01-26 16:00 531 查看
ios开发-判断手机反转--个人学习之路的总结。

//监听手机方向改变事件
[[NSNotificationCenter defaultCenter] addObserver:self
     selector:@selector(orientationChanged)
     name:UIDeviceOrientationDidChangeNotification
      object:nil];

//处理函数
-(void) orientationChanged
{
   switch ([[UIDevice currentDevice]orientation]) {
      case  UIDeviceOrientationPortrait:
         NSLog(@"portrait");
      break;
      case  UIDeviceOrientationPortraitUpsideDown:
         NSLog(@"portraitUpSideDown");
         break;
      case  UIDeviceOrientationLandscapeLeft:
         NSLog(@"landscapeLeft");
         break;
      case  UIDeviceOrientationLandscapeRight:
         NSLog(@"landscapeRight");
         break;
      case  UIDeviceOrientationFaceDown:
         NSLog(@"facedown!!");
         break;
      case  UIDeviceOrientationFaceUp:
          NSLog(@"FaceUp");
          break;
      default:
          break;
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios开发 object 手机