我正在开发一个iPhone应用程序。在这个应用程序中,UIViewController(vc1)呈现另一个UIViewController(vc2)。 vc1支持纵向和横向方向; vc2仅支持纵向方向。
答案 0 :(得分:8)
我向Apple报告了一个错误,我收到了以下回复:
“Engineering已根据以下信息确定此问题的行为符合预期:
演示行为是正确的 - 如果它在以前的版本中表现不同,那就是一个错误。行为中可以想象的意外变化是关于VC1的解散,它不再获得旋转回调,但它将以纵向布局。
当视图控制器自行调出时,还有其他方法可以确定您的方向。由于各种原因,依赖于旋转回调被证明是有问题的。
通常,viewController旋转回调在两种情况下发生:
尝试在iOS 5中使用viewWillLayoutSubviews:“
答案 1 :(得分:4)
在iOS5上测试我的应用时遇到了类似的问题。如果在模态视图控制器处于活动状态时方向发生变化,则主视图控制器中的子视图布局会变得混乱。
我所做的是将当前方向标志存储在主控制器中。该标志在主控制器的两个位置更新
我通过比较当前方向和存储值来编写调整子视图的所有逻辑。如果它们不同 - 更新存储的方向,请更新您的子视图。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Any orientation is OK
return YES;
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
portrait = UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
// Code to update subview layout goes here
}
-(void)viewWillLayoutSubviews
{
BOOL isPortraitNow = UIInterfaceOrientationIsPortrait(self.interfaceOrientation);
if(isPortraitNow != portrait)
{
DLog(@"Interfaceorientation mismatch!, correcting");
portrait = isPortraitNow;
// Code to update subview layout goes here
}
}