首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么视图的淡出效果不起作用?

为什么视图的淡出效果不起作用?
EN

Stack Overflow用户
提问于 2012-08-31 01:13:25
回答 1查看 236关注 0票数 0

我将内容作为documenView添加到滚动视图中,并使用以下代码来淡出我的documentView:

代码语言:javascript
复制
- (IBAction)deleteAllRules:(id)sender {

    NSViewAnimation * deleteListOfRulesViewAnimation;
    NSRect viewRect;
    NSMutableDictionary* animDict;

    // Create the attributes dictionary
    animDict = [NSMutableDictionary dictionaryWithCapacity:3];
    viewRect = listOfRulesView.frame;

    // Specify which view to modify.
    [animDict setObject:listOfRulesView forKey:NSViewAnimationTargetKey];

    // Specify the starting position of the view.
    [animDict setObject:[NSValue valueWithRect:viewRect] forKey:NSViewAnimationStartFrameKey];

    // Shrink the view from its current size to nothing.
    NSRect viewZeroSize = listOfRulesView.frame;
    viewZeroSize.size.width = 0;
    viewZeroSize.size.height = 0;
    [animDict setObject:[NSValue valueWithRect:viewZeroSize] forKey:NSViewAnimationEndFrameKey];

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

    // Create the view animation object.
    deleteListOfRulesViewAnimation = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray
                                                               arrayWithObjects:animDict, nil]];
    // Set some additional attributes for the animation.
    [deleteListOfRulesViewAnimation setDuration:1.5];    // One and a half seconds.
    [deleteListOfRulesViewAnimation setAnimationCurve:NSAnimationEaseIn];
    [deleteListOfRulesViewAnimation setDelegate:self];

    // Run the animation.
    [deleteListOfRulesViewAnimation startAnimation];

    // The animation has finished, so go ahead and release it.
    [deleteListOfRulesViewAnimation release];

}

但是在没有淡出效果的情况下查看隐藏。为什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-31 04:31:42

对于10.5+代码,建议使用核心动画。

使用核心动画的最简单方法是使用动画器代理。例如,可以通过设置视图的alpha值动画来实现淡出效果:

代码语言:javascript
复制
[[myView animator] setAlpaValue:0.0f]

您可以使用以下命令更改动画持续时间:

代码语言:javascript
复制
[[NSAnimationContext currentContext] setDuration:0.4f]
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12202080

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档