Cocoa “首选项”窗口中的动画帧
查看许多OSX应用程序,我经常看到首选项窗口框架根据工具栏按钮激活的视图内容而上下变化Cocoa “首选项”窗口中的动画帧,cocoa,Cocoa,查看许多OSX应用程序,我经常看到首选项窗口框架根据工具栏按钮激活的视图内容而上下变化 我想知道是否有一种方法可以自动调整帧大小尺寸,或者唯一的方法是通过编程调整大小和动画 我认为您只能使用NSWindow的setFrame:display:animate:我不认为窗口可以自动调整大小。因此,当您更改内容时,可以执行以下操作: NSRect oldContentFrame = [oldContentView frame]; NSRect newContentFrame = [newContent
我想知道是否有一种方法可以自动调整帧大小尺寸,或者唯一的方法是通过编程调整大小和动画 我认为您只能使用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/down
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];
看看戴夫·巴顿的作品。它允许您完全按照自己的意愿进行操作,并且几乎所有的配置都是在Interface Builder中完成的。您可以使用库RHPreferencesWindowController。它很容易使用
我更喜欢一开始自己创建它:只是出于好奇,链接的控制器源代码不再可访问,你知道如何获取副本吗?蒂亚!