Cocoa:NSView动画 [英] Cocoa: NSView Animation

查看:701
本文介绍了Cocoa:NSView动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一样简单,因此我不能为我的生活找到什么问题,我通过文档作为指南,但它仍然没有工作。我有一个更大的观点内的视图。 IBAction应该淡出内部视图...就是这样。这是我有:

This is as simple as can be so I can't for the life of me find what's wrong, I looked through the documentation as a guide but it still didn't work. I have a view inside a larger view. An IBAction is supposed to fade out the inner view... that's it. Here's what I've got:

NSViewAnimation *theAnim;
NSMutableDictionary *viewDict;

// Create the attributes dictionary for the view.
viewDict = [NSMutableDictionary dictionaryWithCapacity:2];

// Set the target object to be the view.
[viewDict setObject:_innerView forKey:NSViewAnimationTargetKey];

// Set this view to fade out
[viewDict setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];

theAnim = [[NSViewAnimation alloc] initWithViewAnimations:@[viewDict]];

// Set some additional attributes for the animation.
[theAnim setDuration:1.0];

// Run the animation.
[theAnim startAnimation];

我用NSLogs检查了viewDict和theAnim,我几乎从一个旧的程序复制这个工作,这是工作,现在找不到什么错。

I checked the viewDict and theAnim with NSLogs and neither are nil. I pretty much copied this from an old program I had where this was working, can't find what's wrong now.

我在xcode 5.1.1,感谢

I'm on xcode 5.1.1, thanks for the help.

推荐答案

现代方法更容易:

[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
    context.duration = 1;
    view.animator.alphaValue = 0;
}
completionHandler:^{
    view.hidden = YES;
    view.alphaValue = 1;
}];

如果视图层次是基于layer的,它实际上就足够了:

If the view hierarchy is layer-backed, it's actually sufficient to do:

view.animator.hidden = YES;

这篇关于Cocoa:NSView动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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