Cocoa auto-resizable window
How can I make my NSWindow with NSTabView smoothly resize when user clicks a tab? I want it to like "System P开发者_运维百科referances" application: window changes its size according to content.
Use NSWindow's setFrame:animated: method. If you want to resize the window down, make sure you decrease the y coordinate of the origin by the same amount you increase the size of the window. To also resize the views in the window, make sure you set up their autoresizing properties correctly.
NSWindow *window;
CGFloat widthChange, heightChange;
NSRect frame = [window frame];
frame.size.width += widthChange;
frame.size.height += heightChange;
frame.origin.y -= heightChange;
[window setFrame:frame animated:YES];
精彩评论