2010-12-22 51 views
1

所以我嘗試使用此代碼視圖之間切換:問題使用CATransitions切換視圖

CATransition *applicationLoadViewIn = [CATransition animation]; 

    [applicationLoadViewIn setDuration:1]; 

    [applicationLoadViewIn setType:kCATransitionReveal]; 

    [applicationLoadViewIn setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]]; 

    MyViewControllerClass *theControllerIAmSwitchingTo = [[MyViewControllerClass alloc] init]; 

    [[theControllerIAmSwitchingTo.view layer] addAnimation:applicationLoadViewIn forKey:kCATransitionReveal]; 

但是,該代碼不起作用。沒有錯誤,並且代碼執行得很好,但它沒有做任何事情。我在這裏有什麼錯誤?

+0

你在模擬器上測試它嗎? – 2010-12-22 07:20:33

回答

1

您需要將動畫添加到父視圖層,然後將該視圖添加爲父視圖的子視圖。

所以不是

[[theControllerIAmSwitchingTo.view layer] addAnimation:applicationLoadViewIn forKey:kCATransitionReveal]; 

您需要使用

[parentView.layer addAnimation:animation forKey:kCATransitionReveal]; 
[parentView addSubview:theControllerIAmSwitchingTo.view]; 
1

只是不喜歡它:

CATransition *applicationLoadViewIn = [CATransition animation]; 

    [applicationLoadViewIn setDuration:1]; 

    [applicationLoadViewIn setType:kCATransitionReveal]; 

    [applicationLoadViewIn setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]]; 

    MyViewControllerClass *theControllerIAmSwitchingTo = [[MyViewControllerClass alloc] init]; 

    [[theControllerIAmSwitchingTo.view layer] addAnimation:applicationLoadViewIn forKey:kCATransitionReveal]; 

    [self.navigationController pushViewController:theControllerIAmSwitchingTo animated:NO]; 

我注意到的問題是,您不添加您的視圖您的導航堆棧,這就是爲什麼你的視圖不會被加載,你看不到動畫。