3

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

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

这是我添加到 - (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];
...

有没有一个很好的例子来说明如何做到这一点或结合这些动画的一些规则?

4

1 回答 1

1

代替

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

你要

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

您可能需要调整动画值,可能通过使用 CABasicAnimation

于 2010-05-25T13:05:12.873 回答