2012-01-16 3 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"];