2012-04-10 7 views
3

2つ目のアニメーションを呼び出した後、1つのアニメーションを永久に続けることはできますか?例えば:UIView 2つのアニメーションが共存する

1) 2脈動オブジェクトを起動する)、その脈動 3ながらそれを移動)は、第2のアニメーションが無限に最初のものを停止している以外は

すべての作品脈動続けます。以下 は、いくつかのサンプルコードです:

//Pulsate ** 

     [UIView animateWithDuration:0.25 
           delay:0 
          options: (UIViewAnimationCurveEaseOut | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionRepeat) 
         animations:^{ 
          CGAffineTransform currentTransform = self.transform; 
          CGAffineTransform newTransform1 = CGAffineTransformScale(currentTransform, .95, .95); 
          [self setTransform:newTransform1]; 
          CGAffineTransform newTransform2 = CGAffineTransformScale(currentTransform, 1, 1); 
          [self setTransform:newTransform2]; 
         } 
         completion:nil];  


//Move ** 
    [UIView animateWithDuration:0.30 
         delay:0 
        options: (UIViewAnimationCurveEaseOut | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState) 
       animations:^{ 
        [[(UIPinchGestureRecognizer*)sender view] setCenter:CGPointMake(myAppDelegate.MCViewReference.center.x-300, myAppDelegate.MCViewReference.center.y)]; 
       } 
       completion:^(BOOL finished){ 
       }];  

答えて

5

ブロックベースのアニメーションでは、このようにすることはできません。 CABasicAnimationの明示的なアニメーションを使用してアニメーションを分割する必要があります。脈動効果のアニメーションを1つ作成し、無限に繰り返すように設定します。次に、中心(アニメーションまたはアニメーションではない)を設定することで、それを動かすことができます。

CABasicAnimation *pulsation = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; 
pulsation.fromValue = [NSNumber numberWithFloat:0.95f]; 
pulsation.toValue = [NSNumber numberWithFloat:1.f]; 
pulsation.duration = 0.25f; 
pulsation.autoreverses = YES; 
pulsation.repeatCount = INFINITY; 

[self.layer addAnimation:pulsation forKey:@"pulse"]; 

レイヤーにアニメーションを追加すると、アニメーションが開始されます。アニメーションを削除するには、単に[self.layer removeAnimationForKey:@"pulse"またはremoveAllAnimations:を呼び出します。

1

あなたはフェーズにあなたのアニメーションを分離し、次のフェーズを開始するには、完了ブロックを使用することができます。