开发者

Fading in one view for another

Here's my code:

- (IBAction)showTaskDetailView:(id)sender {
    [window setContentView:viewTaskView];
}

How would I fade out the current开发者_高级运维 view and fade in the detail view?


Don't change the content view; put both views in the same content view, and use NSViewAnimation to fade one out and the other in.


Example code here (tweaked slightly):

- (void)crossFadeWithOld:(NSView *)oldView andNew:(NSView *)newView
{
    [window setContentView:newView];

    NSDictionary *oldFadeOut = nil;
    if (oldView != nil) {
        oldFadeOut = [NSDictionary dictionaryWithObjectsAndKeys:
                      oldView, NSViewAnimationTargetKey,
                      NSViewAnimationFadeOutEffect,
                      NSViewAnimationEffectKey, nil];
    }
    NSDictionary *newFadeIn;
    newFadeIn = [NSDictionary dictionaryWithObjectsAndKeys:
                 newView, NSViewAnimationTargetKey,
                 NSViewAnimationFadeInEffect,
                 NSViewAnimationEffectKey, nil];

    NSArray *animations;
    animations = [NSArray arrayWithObjects:
                  newFadeIn, oldFadeOut, nil];

    NSViewAnimation *animation;
    animation = [[NSViewAnimation alloc]
                 initWithViewAnimations: animations];

    [animation setAnimationBlockingMode: NSAnimationBlocking];
    [animation setDuration: 0.5]; // or however long you want it for

    [animation startAnimation]; // because it's blocking, once it returns, we're done

    [animation release];    

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜