1.屏幕旋转控制在Targets -> General -> Deployment Info -> Device Orientation 选择需要支持的方向
2.如果选择支持多个方向,在某些画面又只允许支持一个方向,那么在对应的ViewController中添加如下代码:
- (BOOL)shouldAutorotate NS_AVAILABLE_IOS(6_0)
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations NS_AVAILABLE_IOS(6_0)
{
return 支持的方向;
}
3.自动旋转时,很多时候我们需要重新调整画面各控件的大小以及位置,此时有两种方法:
1)在检测到设备旋转时,手动调整视图中的对象。
2)为视图设计两种版本,一种用于横向,一种用于纵向。
为设图设计两种版本就不用说啦,来说说第一种方式。
如何检测到设备旋转?有两种方式
(1)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(调整方法)
name:UIDeviceOrientationDidChangeNotification
object:nil];
(2)覆盖willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
以上检测到设备旋转后根据设备方向来做调整