如何在Cocoa中带来自定义视图的同时制作幻灯片动画? [英] How to make an slide animation while bringing an custom view in Cocoa?

查看:84
本文介绍了如何在Cocoa中带来自定义视图的同时制作幻灯片动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,当点击一个按钮时,自定义视图应该从一侧滑动。实际上只是一个窗口出现,但我想有一个像iOS导航控制器。如何做到这一点?这是一个Mac OS X应用程序。

I'm developing an app where when clicking to a button, custom view should slide from a side. Actually just a window appears, but I'd like to have something like iOS navigation controller. How this can be done? This is for an Mac OS X app.

推荐答案

您可以使用核心动画过渡。您需要为父视图启用图层备份,然后可以执行

You can use a Core Animation transition. You need to turn on layer backing for the parent view, and then you can do

[[parentView animator] replaceSubview:oldView with:newView];

默认情况下,会交叉淡化视图,但如果你想将其更改为幻灯片动画,将适当的CATransition添加到动画字典。

By default that will crossfade the views, but if you want to change it to a slide animation then you'd add the appropriate CATransition to the animations dictionary.

- (CATransition *)slideAnimation
{
    CATransition *transition = [CATransition animation];
    [transition setType:kCATransitionMoveIn];
    [transition setSubtype:kCATransitionFromRight];
    return transition;
}

,然后在您的parentView中设置该动画

and then to set that animation in your parentView

...
[parentView setAnimations:[NSDictionary dictionaryWithObject:[self slideAnimation] forKey:@"subviews"];
...

这篇关于如何在Cocoa中带来自定义视图的同时制作幻灯片动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆