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

来源:互联网 发布:validform.js ajaxurl 编辑:程序博客网 时间:2024/05/22 04:15

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

在AppDelegate.m文件里面添加

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {      if (_allowRotation == 1) {          return UIInterfaceOrientationMaskLandscapeRight;      }      else      {          return (UIInterfaceOrientationMaskPortrait);      } }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

这样默认所以的页面就是竖屏的,在要强制横屏的页面的控制器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
  • 2
  • 3
  • 1
  • 2
  • 3

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

0 0
原创粉丝点击