如何像 iPhoto 09 中那样执行翻转和放大动画?

发布于 2024-09-02 03:00:26 字数 1300 浏览 6 评论 0原文

我正在开发一个 Cocoa 应用程序,希望能够单击 NSCollectionView 中的一个视图中的按钮,并打开详细信息视图并将其定位到屏幕中间,就像在 iPhoto 09 中单击“我”位于照片的右下角。照片以窗口为中心“翻转”并变大,以显示照片的详细信息。

我猜他们正在使用核心动画来实现这一点。我一直在查看狐猴翻转示例,但是当我尝试修改它以向动画添加重新定位代码时,它会抛出翻转。

这是我添加到 - (IBAction)flip:(id)sender; 的定位代码LemurFlip 的代码:

...
[CATransaction begin]; {
NSSize supersize = contentView.frame.size; // Size of window content view
NSSize subsize = frontView.frame.size; // Size of view we're flipping out
if(!frontView.isHidden)
{
    // Move views to middle of the window
    [[backView animator] setFrameOrigin:NSMakePoint((supersize.width / 2) - (subsize.width / 2), (supersize.height / 2) - (subsize.height / 2))];
    [[frontView animator] setFrameOrigin:NSMakePoint((supersize.width / 2) - (subsize.width / 2), (supersize.height / 2) - (subsize.height / 2))];
}
else {
    // Return views to point of origin
    [[backView animator] setFrameOrigin:NSMakePoint(0, 0)];
    [[frontView animator] setFrameOrigin:NSMakePoint(0, 0)];
}
    [hiddenLayer addAnimation:[self _flipAnimationWithDuration:flipDuration isFront:NO] forKey:@"flipGroup"];
    [visibleLayer addAnimation:[self _flipAnimationWithDuration:flipDuration isFront:YES] forKey:@"flipGroup"];
} [CATransaction commit];
...

是否有一个很好的示例说明如何执行此操作或组合这些动画的一些规则?

I'm developing a Cocoa application and want to be able to click a button in one of the views in my NSCollectionView and have a details view flip open and position to the middle of the screen like it does in iPhoto 09 when you click the "i" in the bottom-right hand corner of a photo. The photo "flips" and grows, centered on the window to reveal details about the photo.

I'm guessing they're using Core Animation to achieve this. I've been looking at the Lemur Flip example, but when I try to modify it to add repositioning code to the animation, it throws off the flip.

Here is the positioning code I've added to the - (IBAction)flip:(id)sender; code of LemurFlip:

...
[CATransaction begin]; {
NSSize supersize = contentView.frame.size; // Size of window content view
NSSize subsize = frontView.frame.size; // Size of view we're flipping out
if(!frontView.isHidden)
{
    // Move views to middle of the window
    [[backView animator] setFrameOrigin:NSMakePoint((supersize.width / 2) - (subsize.width / 2), (supersize.height / 2) - (subsize.height / 2))];
    [[frontView animator] setFrameOrigin:NSMakePoint((supersize.width / 2) - (subsize.width / 2), (supersize.height / 2) - (subsize.height / 2))];
}
else {
    // Return views to point of origin
    [[backView animator] setFrameOrigin:NSMakePoint(0, 0)];
    [[frontView animator] setFrameOrigin:NSMakePoint(0, 0)];
}
    [hiddenLayer addAnimation:[self _flipAnimationWithDuration:flipDuration isFront:NO] forKey:@"flipGroup"];
    [visibleLayer addAnimation:[self _flipAnimationWithDuration:flipDuration isFront:YES] forKey:@"flipGroup"];
} [CATransaction commit];
...

Is there a good example of how to do this or some rules for combining these sort of animations?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝天 2024-09-09 03:00:26

您可能想要调整动画值,而不是

[[backView animator] setFrameOrigin:];
[[frontView animator] setFrameOrigin:];

您想要的

[hiddenLayer setPosition:];
[visibleLayer setPosition:];

,也许可以使用 CABasicAnimation

Instead of

[[backView animator] setFrameOrigin:];
[[frontView animator] setFrameOrigin:];

You want

[hiddenLayer setPosition:];
[visibleLayer setPosition:];

You will want to tweak the animations values, maybe by using a CABasicAnimation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文