查看許多OSX應用程序時,我經常會看到首選項窗口框架會根據工具欄按鈕激活的視圖內容長大和縮小。首選窗口中的可可動畫框架
我想知道是否有一種方法來自動調整幀大小尺寸,或者如果唯一的方法是以編程方式調整大小和動畫。
查看許多OSX應用程序時,我經常會看到首選項窗口框架會根據工具欄按鈕激活的視圖內容長大和縮小。首選窗口中的可可動畫框架
我想知道是否有一種方法來自動調整幀大小尺寸,或者如果唯一的方法是以編程方式調整大小和動畫。
我想你只能使用NSWindow的setFrame:display:animate:我不認爲窗口可以自動調整大小。所以當你改變內容你可以做這樣的事情:
NSRect oldContentFrame = [oldContentView frame];
NSRect newContentFrame = [newContentView frame];
float widthDifference = oldContentFrame.size.width - newContentFrame.size.width;
float heightDifference = oldContentFrame.size.height - newContentFrame.size.height;
// Change the size of the window by the difference between the two views
// and move the frame up
NSRect windowFrame = [window frame];
windowFrame.size.width += widthDifference
windowFrame.size.height += heightDifference;
windowFrame.origin.y -= heightDifference;
// Remove the old content
[oldContentView removeFromSuperview];
// Change the size
[window setFrame:windowFrame display:YES animate:YES];
// Add the new view
[window setContentView:newContentView];
看看Dave Batton的DBPrefsWindowController
。它可以讓你做到你想要的東西,幾乎所有的配置都是在Interface Builder中完成的。
那麼你可以使用一個庫RHPreferencesWindowController。它是易於使用
我喜歡在第一次嘗試創建它自己:P – MatterGoal
只是出於好奇,鏈接控制器源不能訪問了,你知道如何得到一份拷貝? TIA! – Hofi