App 有时候需要给有的界面设置旋转,有的界面不允许旋转。
首先在 AppDelegate.h 文件里添加一个属性
![](https://img.haomeiwen.com/i5360531/617b1157b86d65f8.png)
然后在 AppDelegate.m 文件里实现一个方法
![](https://img.haomeiwen.com/i5360531/9b1ff1bf9f226909.png)
UIInterfaceOrientationMaskAllButUpsideDown :标识除了倒立方向不支持,其他三方方向都支持。
UIInterfaceOrientationMaskPortrait:只支持竖屏。
注:方向的判断是根据屏幕与 home 键的位置关系来判断。
最后在需要横屏的界面 ViewDidLoad 或者 viewWillAppear 调 APPDelegate.h 里的 allowRotation 属性并改变他的值:
![](https://img.haomeiwen.com/i5360531/cb0d6a581485d836.png)
网友评论