UiSplitViewController 不自动旋转

发布于 2024-08-30 15:54:35 字数 333 浏览 6 评论 0原文

我最近遇到了一个问题。我的 iPad 应用程序以某种方式阻止 iPad 自动旋转。我的应用程序加载一个 UISplitView,两个视图控制器都为 shouldAutorotateToInterfaceOrientation: 返回 YES。我已经设置了 info.plist 以包含所有四个方向的“支持的界面方向”键。但是,当我运行应用程序时,旋转设备不会旋转 splitView(即使我收到 UIDeviceOrientationDidChangeNotification)。此外,当我以与 iPad 主屏幕不同的方向退出应用程序时,它不会自动旋转到正确的视图,直到我在应用程序不运行的情况下再次旋转它......任何想法将不胜感激...... 。

I have recently run into a problem. My iPad app is somehow preventing the iPad from auto-rotating. My app loads a UISplitView with both of the view controllers returning YES for shouldAutorotateToInterfaceOrientation:. I have set up my info.plist to include the "Supported interface orientations" key with all four orientations. When I run the app, however, rotating the device does not rotate the splitView (even though I am receiving UIDeviceOrientationDidChangeNotification). In addition, when I exit my app in a different orientation that it started in the iPad home screen doesn't autorotate to the correct view until I rotate it again without my app running.... Any Ideas would be much appreciated....

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

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

发布评论

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

评论(6

倒数 2024-09-06 15:54:35

UISplitViewController 是我曾经使用过的最喜怒无常的视图控制器子类之一。为了使其“完美”工作,它必须作为应用程序窗口中的单个根视图存在。但是,您可以通过一些技巧来解决这个问题 - 就我而言,我需要一个 UITabBarController ,并且至少有两个不同的 UISplitViewController 作为视图控制器 - 但随后您必须处理涉及旋转和 UISplitViewControllerDelegate 回调未触发的奇怪情况。

希望 Apple 将来能够使 UISplitViewController 与其他 UIKit 组件更加兼容......

UISplitViewController is one of the most temperamental view controller subclasses I've ever had to use. In order for it to work "perfectly", it must exist as a single root view in your application's window. You can, however, get around this with some trickery -- in my case, I needed a UITabBarController with at least two distinct UISplitViewControllers as view controllers -- but then you have to take care of weird cases involving rotation and UISplitViewControllerDelegate callbacks not firing.

Here's hoping that Apple makes UISplitViewController more compatible with other UIKit components in the future...

栩栩如生 2024-09-06 15:54:35

我在两个从属 UINavigationController 中遇到了同样的问题。就我而言,一旦我覆盖左侧控制器中的 shouldAutorotateToInterfaceOrientation: 始终返回“YES”,旋转就开始工作。

I ran into this same problem with two subordinate UINavigationControllers. In my case the rotation started working once I overrode shouldAutorotateToInterfaceOrientation: in the left controller to always return 'YES'.

欲拥i 2024-09-06 15:54:35

我发现这工作得很好 - 提供 UISplitViewController 的两个子项都实现了 shouldAutorotateToInterfaceOrientation

即,如果您有类似的东西:

        MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController_iPad" bundle:nil];
        UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];

        DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController_iPad" bundle:nil];
        UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];

        self.splitViewController.viewControllers = @[masterNavigationController, detailNavigationController];

       self.window.rootViewController = self.splitViewController;

定义的 rootViewController你的 NSApplication
那么 MasterViewController 和 DetailViewController 都应该实现:

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return YES;
}

以确保旋转有效。

I found this to work fine - provided BOTH children of the UISplitViewController implement the shouldAutorotateToInterfaceOrientation:

I.e if you have something like:

        MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController_iPad" bundle:nil];
        UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];

        DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController_iPad" bundle:nil];
        UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];

        self.splitViewController.viewControllers = @[masterNavigationController, detailNavigationController];

       self.window.rootViewController = self.splitViewController;

to define the rootViewController of your NSApplication
then both MasterViewController and DetailViewController should implement:

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return YES;
}

as to ensure that rotation works.

烛影斜 2024-09-06 15:54:35

您的 UISplitViewController 是否设置为根视图控制器?如果没有,这可能是您的问题的原因。我遇到了类似的问题 - 状态栏会旋转,但我的详细信息和主视图将保持不变。我重新排列了视图,使 UISplitViewController 成为根,然后我的“主菜单”作为模式视图控制器呈现在分割视图之上,这使得旋转问题消失了。

根据 iPad 编程指南 ,“分割视图控制器的视图应始终安装为应用程序窗口的根视图。”

希望这有帮助。

Is your UISplitViewController set as your root view controller? If not, that may be the cause of your problem. I was having a similar issue - the status bar would rotate but my detail and master views would stay in place. I rearranged the views so that the UISplitViewController was the root and then my 'main menu' was presented as a modal view controller on top of the split view, and it made the rotation problem go away.

According to the iPad Programming Guide, "The split view controller’s view should always be installed as the root view of your application window."

Hope this helps.

总攻大人 2024-09-06 15:54:35

我现在也有同样的问题。原因是除了 UISplitViewController 的视图之外,我不小心向窗口添加了另一个视图。删除额外的视图使其工作。

I had the same problem right now. The reason was that I had accidentally added another view to the window in addition to UISplitViewController's view. Removing the extra view made it work.

月棠 2024-09-06 15:54:35

您说您的第一个问题是 UISplitView 阻止您自动旋转。尝试使用 Splitview 的子类来代替自动旋转:

@implementation SplitViewControllerRotating
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    NSLog(@"SplitViewControllerRotating shouldAutorotate");
    return YES;
}
@end

你的第二个问题听起来很奇怪。你说退出应用程序后你必须旋转,以便你的 iPad 识别界面方向。无法帮助你。

You said that your first Problem is, that the UISplitView prevents you from autorotating. Try to use a Subclass of Splitview instead that enbales autorotating:

@implementation SplitViewControllerRotating
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    NSLog(@"SplitViewControllerRotating shouldAutorotate");
    return YES;
}
@end

Your second problem sounds weird. You said after exiting your app you have to rotate, so that your iPad recognizes interface-orientation. Cant help you with that.

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