2012-01-16 157 views
1

如何旋轉和翻譯屏幕的一側的UIImageView,然後從另一側回來.. 可以說我有一個輪子,我想旋轉和翻譯從中間再關閉屏幕的左側,然後從右側和背部中間的「回來」 ..旋轉和翻譯UIImageView在屏幕上

我用下面的代碼進行旋轉,並將其翻譯關閉屏幕;

 CABasicAnimation* rotationAnimation; 
     rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; 
     rotationAnimation.toValue = [NSNumber numberWithFloat: -M_PI * 2.0 /* full rotation*/ * 2 * 1 ]; 
     rotationAnimation.duration = 1; 
     rotationAnimation.cumulative = YES; 
     rotationAnimation.repeatCount = 1.0; 
     rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; 
     rotationAnimation.delegate = self; 

     CABasicAnimation* translationAnimation; 
     translationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"]; 
     translationAnimation.toValue = [NSNumber numberWithFloat:-700]; 
     translationAnimation.duration = 1; 
     translationAnimation.cumulative = YES; 
     translationAnimation.repeatCount = 1.0; 
     translationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; 
     translationAnimation.removedOnCompletion = NO; 
     translationAnimation.fillMode = kCAFillModeForwards; 

不知道如果這是正確的路要走,所以請大家幫忙!

回答

3

試試這個,它會爲你工作

CABasicAnimation* rotationAnimation; 
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; 
    rotationAnimation.toValue = [NSNumber numberWithFloat: -M_PI * 2.0 /* full rotation*/ * 2 * 1 ]; 
    rotationAnimation.duration = 1; 
    rotationAnimation.cumulative = YES; 
    rotationAnimation.repeatCount = 1.0; 
    rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; 
    rotationAnimation.delegate = self; 

    CABasicAnimation* translationAnimation; 
    translationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"]; 
    translationAnimation.toValue = [NSNumber numberWithFloat:-700]; 
    translationAnimation.duration = 1; 
    translationAnimation.cumulative = YES; 
    translationAnimation.repeatCount = 1.0; 
    translationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; 
    translationAnimation.removedOnCompletion = NO; 
    translationAnimation.fillMode = kCAFillModeForwards; 



    CAAnimationGroup *group = [CAAnimationGroup animation]; 
    group.animations = [NSArray arrayWithObjects:rotationAnimation,translationAnimation, nil]; 
    group.delegate = self; 
    group.removedOnCompletion = NO; 
    group.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 

    [[self.imageView.layer addAnimation:group forKey:@"randt"];