问题描述:

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?

网友答案:

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.

网友答案:

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:

-(void)setFrame:(CGRect)newFrame
{
    [super setFrame:newFrame];
    [self.superview sizeToFit];
}
相关阅读:
Top