0

スクロールビューに、コンテンツを含むビューをdocumenViewとして追加し、このコードを使用してdocumentViewをフェードアウトします。

- (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];

}

ただし、フェードアウト効果なしで非表示を表示します。なんで?

4

1 に答える 1

4

10.5以降のコードにはCoreAnimationを使用することをお勧めします。

Core Animationを使用する最も簡単な方法は、アニメータープロキシを使用することです。たとえば、ビューのアルファ値をアニメーション化することで、フェードアウト効果を実行できます。

[[myView animator] setAlpaValue:0.0f]

次を使用してアニメーションの長さを変更できます。

[[NSAnimationContext currentContext] setDuration:0.4f]
于 2012-08-30T20:31:42.030 に答える