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

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

在AppDelegate.m文件里面添加

- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window

{

if(_allowRotation ==1)

{

returnUIInterfaceOrientationMaskLandscapeRight;

}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 个别页面强制横屏,其他页面竖屏)