可可 – NSWindow翻转动画 – 喜欢iWork

可可 – NSWindow翻转动画 – 喜欢iWork,第1张

概述我正在尝试实现与iWork相同的窗口翻转 – https://dl.dropbox.com/u/2338382/Window%20Flipping.mov 但是,我似乎无法找到一种直截了当的方式.一些教程建议将窗口两侧的快照图像粘贴在一个更大的透明窗口中,并为其设置动画.这可能有用,但看起来有点hacky,示例代码总是臃肿.一些教程建议使用私有API,因为这个应用程序可能是MAS绑定的,我想避免这 我正在尝试实现与iWork相同的窗口翻转 –

https://dl.dropbox.com/u/2338382/Window%20Flipping.mov

但是,我似乎无法找到一种直截了当的方式.一些教程建议将窗口两侧的快照图像粘贴在一个更大的透明窗口中,并为其设置动画.这可能有用,但看起来有点Hacky,示例代码总是臃肿.一些教程建议使用私有API,因为这个应用程序可能是MAS绑定的,我想避免这种情况.

我应该怎么做呢?有人有任何提示吗?

NSWindow FlipPing

我已经将下面链接的古代代码重写为NSWindow FlipPing.您可以从my misc. Cocoa collection on GitHub,PCSnippets获取这些源文件.

解决方法 您可以使用CoreGraphics框架实现此目的.看看这个:

- (voID) flipwithDuration: (float) duration forwards: (BOol) forwards{  CGSTransitionSpec spec;  CGSTransitionHandle TransitionHandle;  CGSConnection cID = CGSDefaultConnection;  spec.type = CGSFlip;  spec.option = 0x80 | (forwards ? 2 : 1);  spec.wID = [self windowNumber];  spec.backcolor = nil;  TransitionHandle = -1;  CGSNewTransition (cID,&spec,&TransitionHandle);  CGSInvokeTransition (cID,TransitionHandle,duration);  [[NSRunLoop currentRunLoop] runUntilDate:         [NSDate dateWithTimeIntervalSinceNow: duration]];  CGSReleaseTransition (cID,TransitionHandle);}

您可以下载示例项目:here.更多信息here.

更新:

看看this project.这实际上就是你需要的.

About this project:

This category on NSWindow allows you to switch one window for
another,using the “flip” animation popularized by Dashboard Widgets.
This was a nice excuse to learn something about CoreImage and how to
use it in Cocoa. The demo app shows how to use it. Scroll to the end
to see what’s new in this version!

Basically,all you need to do is something like:

[someWindow flipToShowWindow:someOtherWindow forward:YES];

However,this code makes some assumptions: — someWindow (the initial
window) is already visible on-screen. — someOtherWindow (the final
window) is not already visible on-screen. — Both windows can be
resized to the same size,and aren’t too large or complicated — the
latter conditions being less important the faster your cpu/vIDeo card
is. — The windows won’t go away while the animation is running. — The
user won’t try to click on the animated window or do something while
the animation is running.

The implementation is quite straightforward. I move the final to the
same position and size as the initial window. I then position a larger
transparent window so it covers that frame. I render both window
contents into CIImages,hIDe both windows,and start the animation.
Each frame of the animation renders a perspective-distorted image into
the transparent window. When the animation is done,I show the final
window. Some tricks are used to make this faster; the flipPing window
is setup only once; the final window is hIDden by setting its Alpha to
0.0,not by ordering it out and later ordering it back in again,for instance.

The main bottleneck is the CoreImage filter,and the first frame always takes much longer to render — 4 or 6 times what it takes for the remaining frames. I suppose this time is spent with setup and downloading to the vIDeo card. So I calculate the time this takes and draw a second frame at a stage where the rotation begins to show. The animation begins at this point,but,if those first two frames took too long,I stretch the duration to make sure that at least 5 more frames will get rendered. This will happen with slow harDWare or large windows. At the end,I don’t render the last frame at all and swap the final window in instead.

总结

以上是内存溢出为你收集整理的可可 – NSWindow翻转动画 – 喜欢iWork全部内容,希望文章能够帮你解决可可 – NSWindow翻转动画 – 喜欢iWork所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1001213.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存