iOS横竖屏

来源:互联网 发布:网络挣钱路子 编辑:程序博客网 时间:2024/05/21 19:12

iOS APP默认支持四个方向,即Portrait、PortraitUpsideDown、LandscapeLeft、LandscapeRight。在有些画图类、游戏类应用中,需要限制APP仅支持横屏或仅支持竖屏,这就需要在程序中禁止支持其他两个方向。下面以横屏应用为例介绍一下如何进行设置:

首先,在项目的info.plist中去掉竖屏的两个方向,保留横屏方向,如下图所示


然后,在项目中的UINavigationController子类中添加如下代码

- (BOOL)shouldAutorotate

{

return YES;

}


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

{

return UIInterfaceOrientationLandscapeLeft;

}



- (NSUInteger)supportedInterfaceOrientations

{

return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;

}


同时记得在General里面修改




1 0
原创粉丝点击