iOS判断手机方向改变

更新时间:2016-03-16 10:34:18 点击次数:3189次
  1. //监听手机方向改变事件
  2. [[NSNotificationCenter defaultCenter] addObserver:self
  3. selector:@selector(orientationChanged)
  4. name:UIDeviceOrientationDidChangeNotification
  5. object:nil];
  6. //处理函数
  7. -(void) orientationChanged
  8. {
  9. switch ([[UIDevice currentDevice]orientation]) {
  10. case UIDeviceOrientationPortrait:
  11. NSLog(@"portrait");
  12. break;
  13. case UIDeviceOrientationPortraitUpsideDown:
  14. NSLog(@"portraitUpSideDown");
  15. break;
  16. case UIDeviceOrientationLandscapeLeft:
  17. NSLog(@"landscapeLeft");
  18. break;
  19. case UIDeviceOrientationLandscapeRight:
  20. NSLog(@"landscapeRight");
  21. break;
  22. case UIDeviceOrientationFaceDown:
  23. NSLog(@"facedown!!");
  24. break;
  25. case UIDeviceOrientationFaceUp:
  26. NSLog(@"FaceUp");
  27. break;
  28. default:
  29. break;
  30. }
  31. }
复制代码

本站文章版权归原作者及原出处所有 。内容为作者个人观点, 并不代表本站赞同其观点和对其真实性负责,本站只提供参考并不构成任何投资及应用建议。本站是一个个人学习交流的平台,网站上部分文章为转载,并不用于任何商业目的,我们已经尽可能的对作者和来源进行了通告,但是能力有限或疏忽,造成漏登,请及时联系我们,我们将根据著作权人的要求,立即更正或者删除有关内容。本站拥有对此声明的最终解释权。

回到顶部
嘿,我来帮您!