2011-08-10 98 views
0

代碼:我的CAAnimation有什麼問題嗎?

UIView *superView = [self.view superview]; 
CATransition *animation = [CATransition animation]; 
animation.duration = 0.5f; 
animation.timingFunction = UIViewAnimationCurveEaseInOut; 
animation.fillMode = kCAFillModeForwards; 
animation.type = kCATransitionFade; 
animation.subtype = kCATransitionFromTop; 
[root.view removeFromSuperview]; 
[self.view removeFromSuperview]; 
[superView.layer addAnimation:animation forKey:@"removeContentAnimation"]; 

self.view和root.view在「上海華」

當我犯這個動畫,有發生一個錯誤一點機會加入 - 雙方的意見取出從superView中立即回來。在這個快速變化之後,它正常消失。

+1

問題不是很清楚,什麼是錯誤?什麼是self.view和root.view? – Spring

回答

0

檢查出這個數獨:http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/AnimatingViews/AnimatingViews.html#//apple_ref/doc/uid/TP40009503-CH6-SW1

  1. 你不能動畫removeFromSuperView。
  2. 你應該使用塊動畫的意見

這裏是一個簡短的提示:

- (IBAction)hideView:(id)sender 
{ 
    [UIView animateWithDuration:1.0 
     delay: 0.0 
     options: UIViewAnimationOptionCurveEaseIn 
     animations:^{ 
      viewToHide.alpha = 0.0; 
     } 
     completion:^(BOOL finished){ 
      [viewToHide removeFromSuperView]; 
     }]; 
}