Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa “首选项”窗口中的动画帧_Cocoa - Fatal编程技术网

Cocoa “首选项”窗口中的动画帧

Cocoa “首选项”窗口中的动画帧,cocoa,Cocoa,查看许多OSX应用程序,我经常看到首选项窗口框架根据工具栏按钮激活的视图内容而上下变化 我想知道是否有一种方法可以自动调整帧大小尺寸,或者唯一的方法是通过编程调整大小和动画 我认为您只能使用NSWindow的setFrame:display:animate:我不认为窗口可以自动调整大小。因此,当您更改内容时,可以执行以下操作: NSRect oldContentFrame = [oldContentView frame]; NSRect newContentFrame = [newContent

查看许多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/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。它很容易使用


我更喜欢一开始自己创建它:只是出于好奇,链接的控制器源代码不再可访问,你知道如何获取副本吗?蒂亚!