模态视图的 iPad 方向问题

发布于 2024-09-25 22:08:52 字数 198 浏览 2 评论 0原文

我的模态视图旋转有问题。 我以纵向模式创建主视图,然后创建模态视图。一切正常:我可以旋转模态视图并且支持所有方向。 如果我以纵向模式创建主视图,然后以横向旋转,然后创建模态视图...模态处于纵向模式,而不是应有的横向模式。

主视图和模态视图中的shouldAutorotateToInterfaceOrientation都返回YES。

有什么想法吗?

i've a problem with a modal view rotation.
I create a main view in portrait mode, then i create a modal view. Everything works fine: i can rotate the modal view and all orientation are supported.
If i create the main view in portrait mode then rotate in landscape and after that i create my modal view... the modal is in portrait mode and not in landscape as it should be.

Both shouldAutorotateToInterfaceOrientation in main view and modal view return YES.

Any ideas?

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

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

发布评论

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

评论(3

撕心裂肺的伤痛 2024-10-02 22:09:02

遇到了同样的问题,最终修复了模式延迟一秒钟的问题,因此“父”视图控制器可以获得正确的方向。

[self performSelector:@selector(presentLogin) withObject:nil afterDelay:1.0]

现在登录看起来像:

- (void) presentLogin {
LoginVC *loginVC = [[LoginVC alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:loginViewController];
nav.modalPresentationStyle =UIModalPresentationFormSheet;
[self presentViewController:nav animated:YES completion:NULL]; 
}

Had the same issue, finaly fixed delaying the modal for a second, so the 'parent' view controller could get the correct orientation.

[self performSelector:@selector(presentLogin) withObject:nil afterDelay:1.0]

presentLogin looks like:

- (void) presentLogin {
LoginVC *loginVC = [[LoginVC alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:loginViewController];
nav.modalPresentationStyle =UIModalPresentationFormSheet;
[self presentViewController:nav animated:YES completion:NULL]; 
}
抱猫软卧 2024-10-02 22:09:01

如果视图控制器在 iOS 将旋转事件排队之后但在处理旋转事件之前呈现,则可能会发生这种情况。根据观察,我认为旋转事件特定于当前呈现的视图控制器。

这是一种有用的思考方式:

  1. 旋转事件由 iOS 为顶部视图控制器 A 排队。
  2. 您的代码呈现了一个视图控制器 B。
  3. 旋转事件已出列,但它只处理视图控制器 A。

值得庆幸的是,有一个非常简单的修复方法。假设事件队列中有一个旋转事件,并确保您的视图实际上在它之后呈现。您可以通过对新视图控制器的呈现进行排队来完成此操作,而不是直接呈现它。排队到主队列的块将在任何已排队的事件(如旋转事件)之后、但在用户有机会与您的 UI 交互之前执行。

更改

[self performSegueWithIdentifier: @"firstRun" sender: self];

为:

dispatch_async(dispatch_get_main_queue(), ^{
    [self performSegueWithIdentifier: @"firstRun" sender: self];
});

执行此操作后,您会得到以下行为:

  1. 旋转事件由 iOS 为顶部视图控制器 A 排队。
  2. 您的代码调度将呈现新视图控制器的块。
  3. 旋转事件已出列,但它仅寻址视图控制器 A。
  4. 新的视图控制器 B 由您的块呈现。它获得了新的方向。

This can happen if the view controller is being presented after iOS queues a rotate event, but before the rotate event is handled. From observation, I think rotate events are specific to the view controllers currently being presented.

This is a helpful way of thinking of it:

  1. The rotate event is queued up by iOS for the top view controller, A.
  2. Your code presents a view controller, B.
  3. The rotate event is dequeued, but it addresses only view controller A.

Thankfully, there's a really easy fix. Just assume there's a rotate event in the event queue, and make sure your view is actually presented after it. You do this by queuing the presentation of your new view controller, rather than presenting it directly. Blocks queued to the main queue will be executed after any events already queued (like rotate events) but before the user gets a chance to interact with your UI.

Change:

[self performSegueWithIdentifier: @"firstRun" sender: self];

To:

dispatch_async(dispatch_get_main_queue(), ^{
    [self performSegueWithIdentifier: @"firstRun" sender: self];
});

After doing this, you get this behaviour instead:

  1. The rotate event is queued up by iOS for the top view controller, A.
  2. Your code schedules the block that will present the new view controller.
  3. The rotate event is dequeued, but it addresses only view controller A.
  4. The new view controller, B, is presented by your block. It gets the new orientation.
温柔戏命师 2024-10-02 22:09:01

我有同样的问题。我最终通过从主视图控制器(而不是从子视图之一的视图控制器)显示模态视图来解决这个问题。

I had the same issue. I finally worked around it by displaying the modal view from my main view controller (and not from a view controllers of one of the subviews).

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