强制横屏 ios

AppDelegate.h里面添加

@property(nonatomic,assign)NSInteger allowRotation;
在AppDelegate.m文件里面添加

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { if (_allowRotation == 1) { return UIInterfaceOrientationMaskLandscapeRight; } else { return (UIInterfaceOrientationMaskPortrait); } }

这样默认所以的页面就是竖屏的,在要强制横屏的页面的控制器UIViewController里面,引入#import “AppDelegate.h”
然后

-(void)viewDidLoad { [super viewDidLoad]; AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; appDelegate.allowRotation = 1; }

就可以让个别页面单独横屏了,在跳出这个横屏页面前修改状态,如下

AppDelegate *delegate = [[UIApplication sharedApplication]delegate];delegate.allowRotation = 0;

这样既可完整的实现页面的横屏。
以上就可以实现,iOS中将个别页面强制横屏其他页面竖屏,

 

 

xcode配置

image

 

posted @ 2025-09-12 14:33  黄增松  阅读(22)  评论(0)    收藏  举报