0

顔の画像を含むUIImageViewがあり、そのUIImageViewに回転変換アニメーションを適用します。

 self.transform = CGAffineTransformRotate(self.transform, M_PI / 16);

[UIView animateWithDuration:0.5
                  delay:0.0
                options:UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse
             animations:^{

                 self.transform = CGAffineTransformRotate(self.transform, -1 * (M_PI/8));

             }
             completion:^(BOOL completed) {}];

次に、y軸を上下に移動する同じ顔画像の別のアニメーションがあります。

[UIView animateWithDuration:0.2
                      delay:0.0
                    options:UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse
                 animations:^{

                     self.transform = CGAffineTransformMakeTranslation(0, 10);
                 }
                 completion:^(BOOL completed){}];

最初のアニメーションを実行した後、UIImageViewの位置を変更してから、2番目のアニメーションを開始する必要があります。

アニメーションを削除し、変換をリセットし、UIImageViewの位置を設定するstopAnimationメソッドがあります。

-(void)stopAnimation:(NSInteger)currentAnimation{

    [self.layer removeAllAnimations];

    [self setTransform:CGAffineTransformIdentity];
    [self setFrame:initFrame];

    CGPoint position = [self getNextPosition:currentAnimation];
    //[self setTransform:CGAffineTransformMakeTranslation(0, 0)];
    CGRect frame = self.frame;
    frame.origin.x = position.x;
    frame.origin.y = position.y;
    self.frame = frame;
}

-(CGPoint)getNextPosition:(NSInteger)currentAnimation{

    CGPoint position = [[positions objectAtIndex:(currentAnimation-1)] CGPointValue];
    NSLog(@"Current animation:%u %f:%f", currentAnimation,position.x,position.y);
    return position;
}

アニメーションなしで位置の変更を実行すると、UIImageViewは画面の正しい位置にありますが、アニメーションを使用して実行すると、アニメーションは正常に機能しますが、UIImageViewの位置が間違っています。

UIImageViewの中心に同じ設定を試みましたが、同じ問題が発生します。

4

1 に答える 1

0

最初のアニメーションの長さだけ 2 番目のアニメーションをオフセットしてみてください。

[UIView animateWithDuration:0.2
                      delay:0.51 //delay by the duration of the first animation
                    options:UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse
                 animations:^{
                     self.transform = CGAffineTransformConcat(self.transform, CGAffineTransformMakeTranslation(0, 10));
                 }
                 completion:^(BOOL completed){}];

最初のアニメーションの完了ブロックに 2 番目のアニメーション ブロックを配置することもできます。

于 2013-03-12T16:12:53.217 に答える