在 iPad 应用程序中旋转视图(以及调整其中的元素大小)时出现问题
iPad 上的旋转让我做了一场噩梦。我到处寻找一些教程,但似乎没有什么真正适合我想要的。 (可能没有寻找正确的东西?!)
默认情况下,我有一个纵向视图,它是视图内的图像和按钮。当我旋转时,我发现如果是横向的,这可以解决。然后我尝试设置 uiview 的框架大小以很好地适应屏幕。
如果我让它自动调整大小,它只会拉伸并填充屏幕。这是我不想要的。 但问题是,当我调整大小时,按钮也会调整大小,但比例与图像不同。
我的问题是:调整视图大小的最佳方法是什么。我想简单地将 uiview 缩小 60%,然后它会以相同的 60% 调整该视图中所有内容的大小。我认为目前有效的唯一方法是创建两个视图......但这是工作和维护的两倍!
我尝试过弄乱界面生成器中的自动调整大小箭头,但这似乎又把事情搞砸了!
我完全迷失在这里了!感谢您提供任何信息
I'm having a nightmare with the rotation on iPad. I've searched all over the place for some tutorials, but nothing seems to really be for what I want. (Possibly not searching for the right thing?!)
I have a portrait view by default which is an image and a button inside the view. When I rotate, I detect this can work out if it's landscape. I then try to set the frame size of the uiview to fit nicely on the screen.
If I let it autoresize, it simply stretches and fills the screen. This I don't want.
but the trouble is, when I resize, the button gets resized too, but not in the same ratio as the image.
My question is: What's the best way to resize the view. I wanted to simply reduce the uiview by say 60% and it resizes EVERYTHING in that view with the same 60%. The only way I see this is working at the moment is to create two views... but that's twice the work and maintenance!
I've tried messing with the autosizing arrows in Interface builder, but that again seems to screw things up more!
I'm completely lost here!! Thanks for any info
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您遇到的问题是视图会自动调整为屏幕比例。在纵向方向的 iPad 上,屏幕尺寸为 1024x768。旋转到横向后,原点也会旋转,屏幕内容会倾斜或拉伸到 768x1024。
您需要做的是覆盖
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientationuration:(NSTimeInterval)duration
旋转视图的
UIViewController
的 消息。该消息在旋转的动画块内调用。您只需将子视图(按钮)的框架大小设置为最适合您的值即可。有一次我在旋转 OpenGL 视图时遇到了问题。旋转到横向时视图的内容被拉伸。由于无法更改动画块内的任何 OpenGL 矩阵,我发现的唯一解决方案是使视图成为二次方并将原点设置在屏幕边界后面(在 -x 方向)。您还必须覆盖该消息,以在横向模式下重置屏幕上方(沿 -y 方向)边界的原点,以将视口保持在屏幕中间。这样视图就可以保持其比例。无论哪种解决方案最适合您,覆盖此消息都应该可行。The problem you have there is that the view is automatically resized to the screen ratio. On an iPad in Portrait Orientation the screen size is 1024x768. After the rotation to Landscape the origin rotates too and your screen content is skewed or stretched to 768x1024.
What you need to do is to override the
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
message of the
UIViewController
of the view which rotates. This message is called within the animation block of the rotation. You just set the framesize of your subviews (the button) to whatever is best for you. Once i had a problem with rotating an OpenGL view. The content of the view was stretched when rotating to landscape. Since it is not possible to alter any OpenGL matrices within the animation block the only solution i found was to make the view quadratic and to set the origin behind the bounds of the screen (in -x direction). You have to override the message also to reset the origin above the screen (in -y direction) bounds in landscape mode, to keep the viewport in the middle of the screen. That way the view kept its ratio. Whatever solution is best for you, overriding this message should work out.您是否尝试过禁用 UIView 上的 autoresizesSubviews 属性?当您调整视图大小时,它应该防止子视图发生任何大小更改。
Have you tried disabling the autoresizesSubviews property on your UIView? It should prevent any size changes on the subviews when you resize your view.