我想使ViewController成为一个肖像和ViewController B的景观。当它运行时,即使我将应用程序代理设置为横向更改,所有内容都会显示。你能告诉我该怎么做吗?以下是我的工作..
ViewController A将查看控制器B:
AppDelegate *appDelegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
appDelegate.restrictRotation = TRUE;
MapViewController * sliderVC = [[MapViewController alloc] init ];
sliderVC.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:sliderVC animated:NO completion:nil];
sliderVC.view.backgroundColor = [UIColor clearColor];
AppDelegate.m
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if(self.restrictRotation)//set the bool value to view controller which you want to load in landscape
return UIInterfaceOrientationMaskLandscapeRight;
else
return UIInterfaceOrientationMaskPortrait;
}
答案 0 :(得分:1)
确保您支持所需的方向:
项目>目标>一般
答案 1 :(得分:0)
您应该在View Controller B上覆盖以下方法:
func shouldAutorotate() -> Bool
func supportedInterfaceOrientations() -> Int
func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation
您在AppDelegate中覆盖的方法适用于整个应用。
答案 2 :(得分:0)
我建议您查看相关文档。
基本上这是你需要为所有视图控制器做的事情:
#pragma mark Orientation handling
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}