在 iPad 上处理多个窗口的方向

发布于 2024-09-26 06:46:20 字数 583 浏览 8 评论 0原文

我有一个 iPad 应用程序,它在两种状态之间切换,一种使用 SplitView,另一种使用 TableView。

目前我有一个 UIWindow 对象,并使用以下代码在视图之间切换

-(void) switchToStateA {
[viewControllerB.view removeFromSuperview];
[window addSubview:viewControllerA.view];
}
-(void) switchToStateB {
[viewControllerA.view removeFromSuperview];
[window viewControllerB.view];
}

一切工作正常,除非我更改设备方向。更改方向和切换状态后,更改期间未激活的状态仍处于其旧状态的框架中(在显示屏边缘留下黑色区域)。如果我再次改变方向,新状态将被修复。

我尝试

[viewControllerA.view setNeedsLayout];

在交换视图后添加,但没有效果。

如何确保背景视图控制器获得方向回调,或者如何在切换状态时调用“刷新”?

I have a iPad application which goes between two states, one using a SplitView the other a TableView.

Currently I have a single UIWindow object, and switch between views with the following code

-(void) switchToStateA {
[viewControllerB.view removeFromSuperview];
[window addSubview:viewControllerA.view];
}
-(void) switchToStateB {
[viewControllerA.view removeFromSuperview];
[window viewControllerB.view];
}

Everything works fine unless I change the device orientation. After changing orientation and switching states, the state which was not active during the change is still in the frame of its old state (leaving black areas at the edge of the display). If I change the orientation again the new state will be fixed.

I've tried adding

[viewControllerA.view setNeedsLayout];

after swapping the views but it did not have an effect.

How do I make sure the background view controllers get the orientation callback, or how do I invoke a 'refresh' when I switch state?

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

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

发布评论

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

评论(2

输什么也不输骨气 2024-10-03 06:46:20

这纯粹是我的猜测,但是如果您不是从窗口中删除视图控制器的视图,而是将视图设置为隐藏并使用 exchangeSubviewAtIndex:withSubviewAtIndex:更改用户可见的视图控制器的视图。我想知道操作系统是否正在优化,不向任何视图没有超级视图的视图控制器发送旋转事件。

您甚至可以喜欢动画,在它们切换位置之前将顶部视图的 alpha 淡化为 0,而底部视图的 alpha 淡化为 1。

This is pure speculation on my part, but what if instead of removing the view controller's view from the window, you set the view to hidden and use exchangeSubviewAtIndex:withSubviewAtIndex: to change which view controller's view is visible to the user. I wonder if the OS is optimizing not sending rotation events to any view controllers whose views don't have a super view.

You could even get fancy with animations and fade the top view's alpha to 0 while the bottom view's alpha fades to 1 before they switch places.

无力看清 2024-10-03 06:46:20

设备方向更改由 UIViewController 处理,而不是由独立的 UIView 处理。解决问题的最简单方法是使控制器的视图成为一个哑容器,您永远不会从窗口中删除它。容器视图将始终按照控制器的允许正确旋转。然后,您只需向容器视图添加/删除子视图即可使它们也旋转。在将子视图添加到容器视图之前,不要忘记设置子视图的框架和自动调整大小蒙版。

Device orientation changes are handled by UIViewControllers, not by isolated UIViews. The easiest way to solve your problem is to make the controller's view a dumb container, which you never remove from the window. The container view will always be correctly rotated as permitted by the controller. Then you just add/remove subviews to/from the container view to get them rotated too. Don't forget to set subviews' frames and autoresizing masks before adding them to the container view.

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