方法名称:
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;
}效果展示:
无
本文详细介绍了iOS应用中如何通过`supportedInterfaceOrientations`方法来控制屏幕的方向,包括支持的方向类型及其应用场景,以及在不同设备上的差异。重点讨论了如何在`shouldAutorotate`方法中设置屏幕旋转方向,确保应用在各种设备和旋转状态下的最佳用户体验。

5868

被折叠的 条评论
为什么被折叠?



