主视图不应旋转,但子视图应旋转,包括 UIPopoverController
在花费更多时间进行试验和错误之前,我希望得到一些帮助。
想象一下以下情况:我刚刚开始为 iPad 创建一些东西,它看起来像仪表板,上面有数字刻度盘。旋转 iPad 时(纵向、横向向左等),背景不应旋转,转盘位置应保持不变,但转盘内部应旋转到正确位置。因此,主视图不应旋转,但子视图(表盘内部)应该旋转。我之前在 iPhone 上通过告诉 viewController 仅处于纵向状态然后检查 UIDeviceOrientation 来完成此操作,所以我认为这会很容易。但是当显示 UIPopoverController 时我开始头痛。由于我没有更改 UIInterfaceOrientation,因此 UIPopoverController 将始终处于纵向状态。
理想的解决方案是让主视图(来自 viewController 的 self.view)不观察旋转的变化,但允许子视图执行此操作,但据我了解,这是不可能的。我能想到的唯一其他解决方案是不设置旋转变化的动画,并将子视图(刻度盘)移动到新位置。对它们进行动画处理(子视图)可以让舞蹈随处可见。但我还没有找到关于如何做到这一点的任何好的解决方案。
有人有什么想法吗?
I would appreciate some help before spending any more time on trial and error.
Imagine the following: I'm just starting to create something for the iPad that will look something like a dashboard with a number on dials on it. When rotating the iPad (portrait, landscapeLeft etc) the background should not rotate, the dials position should remain but the inside of the dials should rotate to correct position. So, main view should not rotate, but the subviews (inside of the dials) should. I have done this on the iPhone before by telling the viewController to only be in portrait and then checking UIDeviceOrientation, so I thought this was gonna be easy. But my headache starts when displaying a UIPopoverController. Since I'm not changing the UIInterfaceOrientation, the UIPopoverController will always be in portrait.
Ideal solution would be to have the main view (self.view from the viewController) not observe changes in rotation, but allowing the subviews to do it, but from what I understand that is not possible. Only other solution I could think of is to not animate the change in rotation, and jut move the subviews (dials) into their new position. Animating them (subviews) make the dance all over the place. But I have not found any good solution on how to do that.
Any thoughts anyone?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的想法是正确的,如果主视图不旋转,则子视图自动旋转是不可能的。
我想到的一个解决方法是:旋转视图时产生的动画是视图变换的变化。我非常确定您可以注册以接收设备方向更改,并且当您获得更改时,将变换更改动画化到包含要旋转的所有子视图的容器视图。
编辑:只需阅读有关您拥有弹出控制器的信息。
就弹出窗口而言,API 管理自动旋转的方式是隐藏弹出窗口,然后在旋转结束时再次显示它。实现类似的行为应该不会太难。
我想到的另一件事是:您想要不旋转的只是背景吗?如果只有两种背景,一种用于肖像,另一种用于风景,并且可以在两者之间切换,是否可行?它可能不是最漂亮的,但它可能比您自己重新创建自旋转行为更容易。
You are correct in thinking that if the main view does not rotate, having the subviews automatically rotate is not possible.
A workaround that springs to mind is this: What is animated when you rotate the view is a change in the view's transform. I am pretty sure that you could register to receive device orientation changes and when you get the change, animate a transform change to a container view that contains all the subviews you want to rotate.
Edit: just read about you having a popover controller.
As far as the popover is concerned, the way the API manages autorotation is to hide the popover and then show it again at the end of the rotation. It shouldn't be too hard to implement similar behavior.
Another thing that occurs to me is this: Is what you want to not rotate just a background? Would it work to just have two backgrounds, one for portrait and one for landscape that you could switch between? It might not be the most pretty looking, but it would probably be easier than recreating autorotation behavior yourself.