2

这是我的代码:

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

我将如何淡出当前视图并淡入详细视图?

4

2 回答 2

1

此处的示例代码(稍作调整):

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

}
于 2011-06-24T18:25:04.550 回答
1

不要改变内容视图;将两个视图放在同一个内容视图中,并使用NSViewAnimation淡出另一个视图。

于 2009-12-19T06:04:30.400 回答