---
title: "IOS屏幕旋转控制"
author: "squll369"
date: "2015-11-11T14:27:02Z"
tags: []
categories: ["移动开发"]
slug: "ios"
draft: false
lastmod: "2015-11-11T14:50:30Z"
id: 2256159
url: "https://squll369.iteye.com/blog/2256159"
---

UIViewController里覆盖如下方法：

 

//是否支持旋转  
\-(BOOL)shouldAutorotate{  
return YES;  
}

//支持哪些方向  
\- (UIInterfaceOrientationMask)supportedInterfaceOrientations {  
return UIInterfaceOrientationMaskAllButUpsideDown;  
}

//旋转时做的事  
\- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {  
if(UIInterfaceOrientationLandscapeLeft == toInterfaceOrientation){  
NSLog(@"%f",duration);  
}  
}

 

 利用通知中心来监控方向变动

写道

//利用通知中心来监控方向变动  
\[\[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrg:) name:UIDeviceOrientationDidChangeNotification object:nil];

 

```
- (void)deviceOrg:(NSNotification *) notication{
    UIDevice *device = (UIDevice *)[notication object];
    NSLog(@"orientation:%d",device.orientation);
}
```