Clean easy way to expand window according to subviews
I'm developing an application that uses a master-d开发者_开发知识库etail paradigm with an NSTableView
as the master and an NSView
as the detail. The NSView
gets populated from another NSViewController's
view; I have an individual NSViewController
for each of the detail views and their views are configured in XIBs. What's the cleanest way to have the main window expand only as necessary (preferably with animation) to fit the current detail view (similar to what System Preferences does)? Sorry if this is an elementary question; I'm rather new at desktop Cocoa.
Calculate the size of the window you need to accommodate your master and selected detail view. You can get the size of your detail view:
NSSize detailViewFrameSize = [[detailViewController view] frame].size;
Resize the window:
[window setFrame:frameRect display:YES animate:YES];
Add the detail subview to the specified position.
[[window contentView] addSubview:detailView];
精彩评论