Cocoa auto-resizable window

2019-05-14 08:20发布

How can I make my NSWindow with NSTabView smoothly resize when user clicks a tab? I want it to like "System Preferances" application: window changes its size according to content.

1条回答
啃猪蹄的小仙女
2楼-- · 2019-05-14 08:49

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];
查看更多
登录 后发表回答