【发布时间】:2026-01-31 12:35:01
【问题描述】:
所以我搜索了几页并在这里找到了一些关于堆栈溢出的答案,但似乎没有任何效果。
我有一个根视图控制器。它有 2 个子视图控制器。 (基本内容视图和菜单覆盖)。
目标是让内容视图响应方向变化,但覆盖菜单仅以纵向显示(设计选择在上下文中更有意义)
在我的根 VC 中,我以这种方式添加了我的子视图:
self.contentVC = [DELEGATE.storyboard instantiateViewControllerWithIdentifier:@"content"];
[self addChildViewController:self.contentVC];
self.contentVC.view.frame = self.view.bounds;
[self.view addSubview:self.contentVC.view];
[self.contentVC didMoveToParentViewController:self];
并且根 VC 声明了以下方法:
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
-(BOOL)shouldAutomaticallyForwardAppearanceMethods{
return YES;
}
-(BOOL) shouldAutomaticallyForwardRotationMethods{
return YES;
}
-(BOOL)shouldAutorotate
{
return YES;
}
在我的 conentVC 中:
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
-(BOOL)shouldAutorotate
{
return YES;
}
在menuVC中:
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
-(BOOL)shouldAutorotate
{
return NO;
}
我通过让 rootVC 调用 contentVC 上的一个方法来定位和旋转元素,以编程方式解决了这个问题,现在这工作正常。我主要担心的是,如果苹果增加更多的屏幕尺寸,自动旋转的适应性会更强。我缺少自动旋转解决方案吗?
如上所述,我已经查看了一些帖子,并且知道已经讨论过类似的事情,但我发现的任何解决方案似乎都不起作用。
【问题讨论】:
标签: ios iphone objective-c ios7 autorotate