2012-05-30 94 views
0

我正在編寫Objective-C。我可以用CABasicAnimation爲使用2個動畫的對象同時創建動畫嗎?例如,對象同時縮放和晃動。對象動畫

回答

0

絕對如此。事實上,你可以用CAKeyFrame,CABasic,甚至是UIView動畫。這應該工作的偉大modified from this answer

- (void)earthquake:(UIView*)itemView 
{ 
    CGFloat t = 2.0; 

    CGAffineTransform leftQuake  = CGAffineTransformTranslate(CGAffineTransformIdentity, t, -t); 
    CGAffineTransform rightQuake = CGAffineTransformTranslate(CGAffineTransformIdentity, -t, t); 

    itemView.transform = leftQuake;  // starting point 

    [UIView beginAnimations:@"earthquake" context:itemView]; 
    [UIView setAnimationRepeatAutoreverses:YES]; // important 
    [UIView setAnimationRepeatCount:5]; 
    [UIView setAnimationDuration:0.07]; 
    [UIView setAnimationDelegate:self]; 
    itemView.transform = rightQuake; // end here & auto-reverse 
    [UIView commitAnimations]; 
    [UIView animateWithDuration:1.00 animations:^{ 
     itemView.alpha = 0.0f; 
    }]; 
} 
+0

如果有人能正確地格式化我的代碼,我會非常感激seeig因爲我輸入了這一點,在iPhone上。 – CodaFi