方法名称:
supportedInterfaceOrientations
作用:
返回一个ViewController支持的方向,也就是说你返回这个方向是你屏幕启动后就保持的方向,如让他默认横屏或者竖屏
返回值类型:
返回的方向在UIInterfaceOrientationMask 中定义 (PS:话说左横屏和右横屏右神马区别,竖屏跟倒立竖屏有神马区别,不明白)
- UIInterfaceOrientationMaskPortrait 竖屏
- UIInterfaceOrientationMaskLandscapeLeft 左横屏
- UIInterfaceOrientationMaskLandscapeRight 右横屏
- UIInterfaceOrientationMaskPortraitUpsideDown:倒立竖屏
- UIInterfaceOrientationMaskLandscape:仅支持横屏
- UIInterfaceOrientationMaskAll:支持全部
- UIInterfaceOrientationMaskAllButUpsideDown:除了倒立竖屏都支持
注意事项:
1.仅在IOS6 以后才能用
2.用户在每次改变屏幕转动方向的时候,会先调用shouldAutorotate,再调用它,这就说明,仅在shouldAutorotate方法返回值是YES的时候这个方法才会起作用!
3.如果没有重写这个方法,ipad默认返回的值是UIInterfaceOrientationMaskAll ,iphone默认返回的值是UIInterfaceOrientationMaskAllButUpsideDown,也就是说默认情况下iOS是支持翻转屏幕的
使用方法:
#pragma mark - 设置屏幕支持的翻转方向,在shouldAutorotate为YES时起作用
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
效果展示:
无