1

I'm having a hard time understanding why the following is happening (and how to fix it).

I've created an application using the split-view based application.

I've added a UiBarButtonItem called showTheModal which calls this method found in RootViewController.m:

- (IBAction)showTheModal:(id)sender {
theModalController.modalPresentationStyle = UIModalPresentationFullScreen;
theModalController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:theModalController animated:YES];

if ([detailViewController popoverController] != nil)
    [[detailViewController popoverController] dismissPopoverAnimated:YES];

The BarButtonItem of course, is shown at the bottom of the Default Root Controller (left side of the of the split view in landscape) or at the bottom of the popup (if in landscape).

The modal view is dismissed by a button placed in a toolbar. It calls the following:

[self dismissModalViewControllerAnimated: YES];

The problem I'm having is if rotate the screen, while the modal is up. Here is what happens in different scenarios (start refers to the orientation when the showTheModal button is hit, end refers to the orientation when I hit the dismissModal button).

1)Start landscape, end landscape: Everything appears fine. willHideViewController and willShowViewController methods are not called in the RootViewController (as expected)

2) Start landscape, end portrait: UI appears fine. willHideViewController is run TWICE (WHY?)

3) Start portrait, end portrait: UI appears fine. willHideViewController is run once (as expected)

4) Start portrait, end landscape: The 'Root List' button remains in the detail view (right side of the split view. Neither willHideViewController and willShowViewController are invoked (WHY??)

Any thoughts as to why #2 and #4 don't behave quite the expected way?

4

5 回答 5

1

不幸的是,这不是一个错误。这似乎是一种预期的行为。

我在 iOS 5.0 的 iOS 发行说明中的​​“注意事项和已知问题”部分中找到了这一点:

iOS 5 中的旋转回调不适用于全屏显示的视图控制器。这意味着如果您的代码在另一个视图控制器上显示一个视图控制器,然后用户随后将设备旋转到不同的方向,则在关闭时,底层控制器(即呈现控制器)将不会收到任何旋转回调。但是请注意,呈现控制器在重新显示时将收到 viewWillLayoutSubviews 调用,并且可以从此方法中查询 interfaceOrientation 属性并用于正确布局控制器。

于 2012-05-31T06:29:03.233 回答
1

我遇到了完全相同的问题(上面的#4)。我使用 来解决它viewDidAppear:animated,然后检查视图的高度以查看它是横向还是纵向。(哎呀,堵嘴等)我对那个“解决方案”一点也不满意。

可能相关:我注意到纵向模式下的按钮在旋转到横向后缓慢消失,即按钮在旋转完成后出现一秒钟。但是,在 Mail.app 中,“收件箱”按钮会在轮换开始后立即消失。Apple 做的事情是否与他们在文档中推荐的不同?也许有一种更有效的方式来显示/隐藏主视图按钮?

于 2010-06-06T14:38:33.170 回答
0

对于诊断,您是否尝试过先关闭弹出视图?或者通过打印记录谁在调用该方法(id) sender

于 2010-05-08T23:18:41.547 回答
0

我遇到了同样的问题。

在回答(2)时,它似乎是一个错误。我注意到,当模式视图被推送到拆分视图上时,方向消息在某处排队并且在模式视图被关闭并且拆分视图可见之前不会被处理,但我仍然希望只得到一个回调。

对于 (4),这似乎也是一个错误。幸运的是,didRotate... 事件仍然通过,所以我的解决方案是继承 UISplitViewController 并在这种情况下显式调用委托的 willShowViewController 方法:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];

    //Work around a bug where UISplitViewController does not send 
    //willShowViewController after a modal is presented in portrait
    //but dismissed in landscape.
    UIInterfaceOrientation orientation = self.interfaceOrientation;
    if ( (orientation == UIInterfaceOrientationLandscapeLeft )
        || (orientation == UIInterfaceOrientationLandscapeRight) )
    {
        UINavigationItem* item = [detail.navigationBar.items objectAtIndex:0];
        UIBarButtonItem* barButtonItem = [item leftBarButtonItem];
        [super.delegate splitViewController:self willShowViewController:master invalidatingBarButtonItem:barButtonItem];
    }
}

这里,“master”是一个 IBOutlet,它指的是 splitview 的主视图控制器(左侧),“detail”是一个用于详细视图控制器(右侧大小)的 IBOutlet。

请注意,在我的例子中,详细视图是一个 UINavigationController。您可能需要不同的代码才能从视图控制器中获取 barButtonItem。

此外,这具有调用 willShowViewController 两次进行正常旋转的副作用,但在我的情况下这不是问题。

于 2010-11-12T02:50:47.567 回答
0

我认为这是一个需要向 Apple Development 报告的错误。

UIModalPresentationPageSheet我通过使用该格式呈现我的模态视图来解决这个问题的一部分。

于 2010-08-23T21:23:52.890 回答