当模式对话框关闭时,iPad UISplitViewController 会不必要地旋转

发布于 2024-09-28 19:07:15 字数 895 浏览 0 评论 0原文

我有一个相当简单的分割视图应用程序,改编自 iPhone 代码。主要功能是在与 iPhone 和 iPad 特定类共享的类中继承和扩充代码。 iPad 应用程序中使用的所有类都具有以下内容:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Overriden to allow any orientation.
    return YES;
}

主视图控制器由 UIToolbar 和 UITableView 组成。在每个阶段(第二阶段)都能正确响应旋转。如果我从此视图中呈现一个模式对话框:

 navigationController = [[UINavigationController alloc] initWithRootViewController:tvc];
 navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
 [self presentModalViewController:navigationController animated:NO];

一切都按预期工作,包括旋转设备,直到我以任何方式关闭对话框:

 [self dismissModalViewControllerAnimated:YES];

此时我的主视图旋转 90 度。我查看了 nib 文件中的设置,一切似乎都很好。有什么建议吗?左侧 UITableView 呈现的模式对话框不会出现此问题。

额外问题:

我发现左侧视图呈现的模式对话框确实有一个故障。但只有一个。如果它以纵向模式的弹出视图呈现,并且设备旋转,那么您会得到一个相当令人印象深刻的图形故障,因为它永远旋转出视图!

I have a reasonably simple split view application adapted from iPhone code. The main functionality is in shared classes with iPhone and iPad specific classes inheriting and augmenting the code. All the classes used in the iPad app have the following:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Overriden to allow any orientation.
    return YES;
}

The main view controller consists of a UIToolbar and a UITableView. The responds to rotations correctly at every stage bar two. If I present a modal dialog from this view:


 navigationController = [[UINavigationController alloc] initWithRootViewController:tvc];
 navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
 [self presentModalViewController:navigationController animated:NO];

Everything works as expected including rotating the device until I dismiss the dialog in any way with:

 [self dismissModalViewControllerAnimated:YES];

At which point my main view rotates 90 degrees. I've looked into the settings in nib files and it all seems to be fine. Any advice? A modal dialog presented by the UITableView on the left hand side does not present this problem.

Bonus Question:

I've discovered the modal dialog presented by the left hand view does have a glitch. But only one. If it is presented by the popover view in portrait mode and the device is rotated you get a rather impressive graphical glitch as it rotates out of the view for ever!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对风讲故事 2024-10-05 19:07:15

正如上面评论中所指出的,我设法将两个视图控制器合并为一个,将处理工具栏 + splitview 控制器的代码合并到 iPad 版本中。本来有一个继承自UITableViewController的公共类,iPad和iPhone版本的代码都继承自这个公共类。
问题是在 iPad 上,我想要顶部有一个工具栏,并且还必须支持 splitview 控制器。这是有问题的,因为该类是 UITableViewController,因此我创建了一个包含工具栏和表视图控制器以及 splitview 代码的父类。
在重构过程中,我将公共类更改为 UIViewController,并进行了更改以在代码中支持 UITableView,就像往常一样以及几本 iPhone 开发书籍中的说明。在 iPhone 版本的类中,我使用必要的方法手动创建 UITableView。在 iPad 版本中,它来自 xib 文件。
这示意性地简化了事情,因为现在主视图在控制器中没有控制器。这也解决了问题。关闭模态对话框时 UI 旋转 90 度的情况不再发生。

As noted in the comment above I managed to merge the two view controllers into one, incorporating the code to handle the toolbar + splitview controller into the iPad version. Originally there was a common class which inherited from UITableViewController, both the iPad and iPhone versions of the code inherited from this common class.
The problem was on the iPad I wanted a toolbar at the top and had to support the splitview controller too. This was problematic given that the class was a UITableViewController so I created a parent class containing the toolbar and the tableview controller plus the splitview code.
In refactoring I changed the common class to a UIViewController and made the changes to support a UITableView in code, as normal and instructed in several iPhone dev books. In the iPhone version of class I manually create the UITableView with the necessary methods. In the iPad version it comes from a xib file.
This schematically simplifies things as now the main view doesn't have a controller within a controller. It also solves the problem. The UI rotating 90 degrees upon closing a modal dialog no longer occurs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文