iOS 个别页面强制横屏,其他页面竖屏

来源:互联网 发布:中邮网络培训学院网址 编辑:程序博客网 时间:2024/05/22 06:24

在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;

这样既可完整的实现页面的横屏。

1 0
原创粉丝点击