iPhone 旋转时自动调整大小的问题
在我的 iPhone 应用程序中,当 iPhone 旋转时,我希望在内容视图中缩放一个视图(我们称之为 RectangleView),以及它的所有子视图。因此,当手机从横向模式旋转到纵向模式时,我希望 RectangleView (及其所有子视图)保持其原始形状和相对位置,但只是变小。我在 Interface Builder 中对其及其所有子视图使用自动调整大小来尝试执行此操作。
现在问题来了。当手机旋转时,矩形视图的所有子视图都会相对于整个内容视图进行缩放和移动,而不是相对于其父视图(即矩形视图)进行缩放和移动。这是一个问题,因为内容视图现在的形状(纵向)与以前(横向)不同,因此屏幕上的所有元素都位于错误的位置,而它们应该在 RectangleView 内按比例缩小。我很困惑,因为其中一些元素甚至移出了 RectangleView,我什至不知道这是可能的,因为它们应该包含在 RectangleView 中。
谁能解释一下这里可能发生的情况,以及我如何缩放 RectangleView 及其所有子视图以保留其原始形状和位置,但只是以较小的比例?提前致谢!
In my iPhone app, I have a view (let's call it RectangleView) within the content view that I'd like to scale, along with all its subviews, when the iPhone is rotated. So, when the phone is rotated from landscape to portrait mode, I'd like RectangleView (and all its subviews) to keep their original shape and position relative to each other, but just get smaller. I am using autoresizing on it and all its subviews in Interface Builder to try and do this.
Now here's the problem. When the phone is rotated, all of RectangleView's subviews scale and move relative to the entire content view, not relative their parent view (which is RectangleView). This is a problem because the content view is now a different shape (portrait) than it was before (landscape), and so all the elements on the screen are in the wrong places, when they should just be scaled down within RectangleView. And I am confused because some of these elements even move out of RectangleView, which I didn't even know was possible since they are supposed to be contained within RectangleView.
Can anyone explain what might be happening here, and how I can just scale RectangleView and all its subviews to retain their original shape and positions, but just on a smaller scale? Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你确定它们是从 RectangleView 中移出的,而不是 RectangleView 正在调整大小并填充内容区域吗?另外,我不确定这是否有什么不同,但我发现我需要在旋转后调用
[view setNeedsDisplay]
才能使我的自定义视图正常工作。Are you sure that they are moving out of the RectangleView, and it isn't that the RectangleView is resizing and filling the content area? Also, I'm not sure if it makes a difference, but I found that I needed to call
[view setNeedsDisplay]
after rotation to make my custom view work properly.