如果子视图更改大小,则调整父视图的大小
我是 Cocoa 新手,正在编写自定义 InspectorView
。 父视图 (InspectorView
) 包含多个子视图 (InspectorCategories
)。
如果我展开一个类别(子视图),我必须调整/重新布局我的父母视图? 我发现通过自动调整大小蒙版这是不可能的 - 这是正确的吗?
我在父母视图中尝试使用 resizeSubviewsWithOldSize
,但是在调整子视图大小时不会调用它。
我怎样才能实现这种行为?
I'm new to Cocoa and I'm programming a custom InspectorView
.
A parent view (InspectorView
) contains several subviews (InspectorCategories
).
If I uncollapse a category (subview) I have to resize/relayout my parents view?
I found out that this is not possible through autoresize masks - Is this correct?
I tried it with resizeSubviewsWithOldSize
in my parents view but this gets not called while resizing the subview.
How can I achieve this behavior?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有两个部分可以完成我认为您想要的事情:
(a)在父视图中,覆盖 sizeThatFits: 方法,以便计算适合周围的新尺寸调整子视图的大小。
(b) 在子视图中,重写 setFrame: 方法,在更改帧大小后,它调用 [self.superview sizeToFit] 来调整超级视图的大小,也许像这样:
There are two parts to accomplish what I think you want:
(a) In the parent view, override the sizeThatFits: method so that it computes a new size that fits around the resized subview.
(b) In the subview, override the setFrame: method and after the frame size is changed, it calls [self.superview sizeToFit] to resize the superview, perhaps like this:
不,不可能通过自动调整蒙版大小来实现。自动调整大小掩码定义当其父视图更改边界时视图如何调整大小。
子视图应该让其超级视图知道它需要什么大小,例如通过委托调用。然后,超级视图应该调整自身和子视图的大小。
No, it is not possible to do through autoresizing masks. Autoresizing mask defines how the view is resized when its superview changes bounds.
The subview should let its superview know what size it needs, for example through a delegate call. The superview then should resize itself and the subview.