【发布时间】:2012-09-29 19:21:30
【问题描述】:
我的应用程序中有一个自定义容器视图控制器,但无法在 iOS 6 中实现与在 iOS 5 中相同的旋转行为。
容器(称为 containerVC)包含两个视图控制器,一个应该保持纵向(portraitVC),一个可以旋转到横向(rotatingVC)。我使用分段控件在它们之间切换。
如果我打开 containerVC 最初显示的是 PortraitVC,然后将手机旋转到横向,portraitVC 不会正确旋转。但是,如果我切换到旋转VC,旋转到横向,然后在手机仍处于横向状态时切换到纵向VC,纵向VC 会错误地绘制横向。
在 iOS 5 中,portraitVC 始终保持纵向。
我在 containerVC 中有这段代码用于切换视图控制器:
- (IBAction)segmentChanged:(id)sender {
UIViewController *toViewController = [self viewControllerForSegmentIndex:self.selectedSegmentIndex];
[self addChildViewController:toViewController];
UIViewController *fromViewController = self.selectedViewController;
[self transitionFromViewController:self.selectedViewController
toViewController:toViewController
duration:0
options:0
animations:^{}
completion:^(BOOL finished) {
self.selectedViewController = toViewController;
[toViewController didMoveToParentViewController:self];
[fromViewController removeFromParentViewController];
}];
}
这个在containerVC中处理旋转:
- (NSUInteger)supportedInterfaceOrientations {
UIInterfaceOrientationMask mask = UIInterfaceOrientationMaskPortrait;
if ([self.selectedViewController respondsToSelector:@selector(supportedInterfaceOrientations)] ) {
mask = [self.selectedViewController supportedInterfaceOrientations];
}
return mask;
}
这在portraitVC中:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
这在rotatingVC中:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
当我在选择rotatingVC 后选择portraitVC 时,容器VC 或portraitVC 上没有调用任何旋转方法或回调。外观方法被调用,并且持有 tableview 的 PortraitVC 在 tableview 回调中获取具有横向几何图形的 UITableViewCells。
如果我们必须让 PortraitVC 支持横向,这不是世界末日,但如果可能的话,为了与应用程序的其他部分保持一致,最好不要这样做。似乎应该有一种方法可以让它工作,因为当您对它们进行子类化并覆盖supportedInterfaceOrientations时,内置的容器VC可以正常工作。
【问题讨论】:
-
从未找到解决此问题的好方法。相反,我现在支持 VC 中的横向,它应该只是纵向。我还向 Apple 提交了一个错误(雷达编号:12394782),因为当调用 transitionFromViewController: 时,似乎应该在容器 vc 上调用 supportInterfaceOrientations。