直接上代码
1.项目的General标签中
勾选Device Orientation 的横竖旋转支持
2.AppDelegate.m 中添加重写
//禁止页面旋屏
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskPortrait;
}
3.在单独需要强制横屏的viewController中添加重写
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationLandscapeRight;
}
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
-(BOOL)shouldAutorotate
{
return NO;
}
本文介绍如何在iOS项目中控制屏幕旋转方向,包括全局禁止旋屏、特定页面强制横屏的方法。通过修改项目的General设置,AppDelegate.m及viewController.m文件中的代码实现。
1469

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



