可可自动调整大小的窗口 [英] Cocoa auto-resizable window

查看:115
本文介绍了可可自动调整大小的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户点击标签时,如何使用NSTabView平滑调整我的NSWindow?我希望它喜欢System Preferances应用程序:窗口根据内容改变其大小。

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.

推荐答案

使用NSWindow的setFrame:animated:方法。如果要调低窗口大小,请确保将原点的y坐标减小与增加窗口大小相同的量。要同时调整窗口中的视图大小,请确保正确设置其自动调整属性。

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];

这篇关于可可自动调整大小的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆