2012-06-12 38 views
0

許多人使用此方法在切換視圖上添加動畫。當我嘗試在添加子視圖時添加動畫效果時,視圖總是閃爍一次,原因是視圖在開始時立即添加子視圖,之後動畫開始。屏幕在通過CATransition添加視圖時閃爍

CATransition *transition = [CATransition animation]; 
transition.duration = 0.35; 
transition.removedOnCompletion = NO; 
transition.fillMode = kCAFillModeForwards; 
transition.type = kCATransitionFade; 
transition.subtype = kCATransitionFromBottom; 
transition.delegate = self; 
[[animationView layer] addAnimation:transition forKey:@"switchView"]; 
OtherViewController *otherController = [[OtherViewController alloc]init:cityID]; 
self.myOtherViewController = otherController; 
[otherController release]; 
[self.view insertSubview:myOtherViewController.view atIndex:1]; 

問題的原因是什麼?如何在沒有flash的情況下實現加載新視圖的動畫?

回答

0

將修改後的fillMode修改爲kCAFillModeBoth後,它可以工作。

transition.fillMode = kCAFillModeForwards;