如何像 iPhoto 09 中那样执行翻转和放大动画?
我正在开发一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想要调整动画值,而不是
您想要的
,也许可以使用 CABasicAnimation
Instead of
You want
You will want to tweak the animations values, maybe by using a CABasicAnimation