1、方向旋转三种枚举
UIDeviceOrientation
设备当前的旋转方向UIInterfaceOrientation
界面当前的旋转方向(控制器)UIInterfaceOrientationMask
界面当前支持的旋转方向
2、方向控制优先级
Appdelegate代码控制 > Xcode
的General
设置(info.plist设置) > 控制器的代码控制
xcode设置
App delegate
界面控制
3、界面控制注意事项
4、单个界面强制旋转
//进入界面:设置横屏
[self setDeviceInterfaceOrientation:UIDeviceOrientationLandscapeLeft];
//方法1和方法2只有在shouldAutorotate返回YES的时候生效
//如果有导航控制器和Tabbar控制器,则要注意控制优先级
//方法1:强制屏幕旋转
- (void)setInterfaceOrientation:(UIInterfaceOrientation)orientation {
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
SEL selector = NSSelectorFromString(@"setOrientation:");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:[UIDevice currentDevice]];
int val = orientation;
[invocation setArgument:&val atIndex:2];
[invocation invoke];
}
}
//方法2:强制屏幕旋转
- (void)setDeviceInterfaceOrientation:(UIDeviceOrientation)orientation {
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:orientation] forKey:@"orientation"];
}
}
5、更新状态栏方向
- 更新状态栏方向
[self setNeedsStatusBarAppearanceUpdate];
- 更新控制器方向
[UIViewController attemptRotationToDeviceOrientation];
6、实战开发2种策略
- 控制权交给当前控制器
- 控制权交给appDelegate控制(通过外部参数控制)