ios中强制UIViewController横屏的问题

首先确认你的工程级别 支持横屏

然后在你的UIViewController中:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
override func shouldAutorotate() -> Bool {
return false
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.LandscapeLeft
}
override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
return UIInterfaceOrientation.LandscapeLeft
}
override func shouldAutorotate() -> Bool { return false } override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { return UIInterfaceOrientationMask.LandscapeLeft } override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation { return UIInterfaceOrientation.LandscapeLeft }
override func shouldAutorotate() -> Bool {
    return false
}
    
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask.LandscapeLeft
}
    
override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
    return UIInterfaceOrientation.LandscapeLeft
}

在启动这个UIViewController中,注意一定要present,不要push,这是个关键

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[self.navigationController presentViewController:controller animated:YES completion:nil];
[self.navigationController presentViewController:controller animated:YES completion:nil];
[self.navigationController presentViewController:controller animated:YES completion:nil];

更多可以参考:http://stackoverflow.com/questions/17063020/how-to-load-a-uiviewcontroller-in-landscape-mode-if-its-parent-is-in-portrait-mo

 

Leave a Reply

Your email address will not be published. Required fields are marked *