代码笔记

// 横屏设定的宏
#define SetScreenOrientation 
- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}
//单斜杠是除法,双斜杠是注释,反斜杠可以链接宏定义,或连接字符串。

旋屏常用解释

  • UIInterfaceOrientationMaskLandscape:支持左右横屏
  • UIInterfaceOrientationMaskAll:支持四个方向旋转
  • UIInterfaceOrientationMaskAllButUpsideDown:支持除了UpsideDown以外的旋转

当前屏幕方向interfaceOrientation的获取,有3种方式可以获取到“当前interfaceOrientation”:

controller.interfaceOrientation,获取特定controller的方向
[[UIApplication sharedApplication] statusBarOrientation] 获取状态条相关的方向
[[UIDevice currentDevice] orientation] 获取当前设备的方向