1

我使用 iOS 5 SDK 创建了一个主从应用程序,打算在设备为纵向时以模态方式显示 UIViewController,在设备为横向时显示 UISplitViewController。

使用以下命令旋转到横向时,模态 VC 会被解除:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    if(UIInterfaceOrientationIsLandscape(toInterfaceOrientation)){
        [self dismissModalViewControllerAnimated:YES];
    }
}

但是 UISplitViewController 永远不会获得旋转事件,因此最终会在横向窗口中以纵向“模式”结束。

我尝试在 DetailViewController 中的 viewWillAppear 中触发旋转,如下所示:

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
    if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
        [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
    }
}

,尝试调用 SplitViewController 的willRotateToInterfaceOrientation,也尝试didRotateFromInterfaceOrientation从我的模态调用 SplitViewController,但没有任何效果。

有任何想法吗?

4

0 回答 0