简体   繁体   中英

Force orientation in ios9

我想在横向模式下的2个viewController和1个viewController中强制使用肖像模式,我尝试了较旧的技术,但是在ios9中不起作用

It's more than likely that you've got some allowed orientations defined in your info.plist . You should check there and remove any entries, as I believe these will override any other values in the project.

You should then be able to set the orientation on each VC with something like:

-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscapeRight;
}

-(BOOL)shouldAutorotate {
return NO;
}

I think the key you need to is Supported interface orientations .

You can set the orientation of the viewcontroller from Xib/Storyboard as each viewcontroller have the property "orientation"

and implement method given below

-(BOOL)shouldAutorotate 
{
     return NO;
}

You can set orientation as bellow in your viewDidAppear method

NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM