2012-04-30 70 views
0

我对Mac开发真的很陌生(虽然我有很多iOS体验),我试图在NSWindow中的NSViewControllers之间切换。这很简单:按下按钮时,显示第二个视图并隐藏第一个视图。这里是我的代码:在NSWindow中切换视图

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { 
    firstView = [[FirstView alloc] initWithNibName:@"FirstView" bundle:nil]; 
    [_window setContentView:menu.view]; 
} 

- (IBAction)openSecondView:(id)sender { 
    secondView = [[SecondView alloc] initWithNibName:@"SecondView" bundle:nil]; 
    [_window setContentView:game.view]; 
} 

我确保该方法被调用,并且该secondView加载正确。这里有什么问题?

回答

3

更简单的方法是将两个视图加载到您的内容视图中,并仅调整alpha值。

- (void) switchToFirstView: (id) sender { 
    [[_secondView animator] setAlphaValue: 0.0f]; 
    [[_firstView animator] setAlphaValue: 1.0f]; 
} 

- (void) switchToSecondView: (id) sender { 
    [[_secondView animator] setAlphaValue: 1.0f]; 
    [[_firstView animator] setAlphaValue: 0.0f]; 
} 

我使用了动画师,使上述过渡褪色的自由,但你也可以去,没有它,如果你喜欢的瞬间切换。

+1

我不知道'animator',谢谢! – Cristian