2012-04-07 3 views
1

私はこのアニメーションを1つの背景画像と、中央にある針の12画像で構成します。実行中のokですが、イメージとイメージを表示するたびに、イメージ間でスムーズに動くようにします。どうやってやるの?ここスムーズな画像アニメーションを作成する方法

私の現在のコードです:

- (IBAction)startAnimation:(id)sender 
{ 
    imgAnimation.frame = CGRectMake(0, 0, 184.5f, 172.5f); 
    imgAnimation.center = CGPointMake(160, 164); 
    imgAnimation.animationImages = [NSArray arrayWithObjects: 
           [UIImage imageNamed:@"pointer01.png"], 
           [UIImage imageNamed:@"pointer02.png"], 
           [UIImage imageNamed:@"pointer03.png"], 
           [UIImage imageNamed:@"pointer04.png"], 
           [UIImage imageNamed:@"pointer05.png"], 
           [UIImage imageNamed:@"pointer06.png"], 
           [UIImage imageNamed:@"pointer07.png"], 
           [UIImage imageNamed:@"pointer08.png"], 
           [UIImage imageNamed:@"pointer09.png"], 
           [UIImage imageNamed:@"pointer10.png"], 
           [UIImage imageNamed:@"pointer11.png"], 
           [UIImage imageNamed:@"pointer12.png"], nil]; 
    [imgAnimation setAnimationRepeatCount:5]; 
    [imgAnimation setAnimationDuration:4.0f]; 
    [imgAnimation startAnimating]; 

}

gauge gauge

+0

あなたはこの質問には、ほんの数時間前に頼ま参照してくださいませんか? http://stackoverflow.com/questions/10053207/how-to-animate-a-set-of-images Dupeアカウント??? –

+0

これは私がしたいことではありません。 –

+0

オクラホマ..ごめんなさい:-)) –

答えて

3

編集:私はもともとUIViewのアニメーションを示唆したが、それは常に介して回転、最短のルートを取ります270度ではなく90度です。これを試してください。Can I use CGAffineTransformMakeRotation to rotate a view more than 360 degrees?

可能な限り滑らかな針アニメーションを得るには、一連の画像を使用しないでください。 UIImageView内で、背景のダイヤルイメージを中心とするビューを持つ単一の針イメージから開始します。次に、UIImageViewのレイヤーのtransformプロパティを回転用の変換で変更します。

ジオメトリを整列させたら、コアアニメーションを使用して、適切な角度の範囲で変化するトランスフォームをアニメートします。ただ、詳しく説明する

imgAnimationはUIImageViewであると仮定すると:

- (IBAction)startAnimation:(id)sender 
{ 
    // This assumes that the center of the needle image is the center of the dial. If they aren't, it's probably simplest to resize the needle image so it is centered. 
    imgAnimation.frame = CGRectMake(0, 0, 184.5f, 172.5f); 
    imgAnimation.center = CGPointMake(160, 164); 

    // The needle image used should show the needle pointing straight up, or some other known direction. 
    imgAnimation.image = [UIImage imageNamed:@"pointer06.png"]; 
    // Position the needle in its position before animating. 
    [imgAnimation.layer setTransform:CATransform3DMakeRotation(-M_PI*3/4, 0, 0, 1)]; 

    // Construct an animation moving the needle to its end position. 
    // Mose of these properties should be self-explanatory. Look up the CABasicAnimation Class Reference if not. 
    CABasicAnimation *needleAnim = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; 
    needleAnim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
    needleAnim.duration = 4; 
    needleAnim.repeatCount = 5; 
    needleAnim.autoreverses = YES; 
    // Setting fillMode means that, once the animation finishes, the needle stays in its end position. 
    needleAnim.fillMode = kCAFillModeForwards; 
    needleAnim.removedOnCompletion = YES; 
    needleAnim.toValue = [NSNumber numberWithFloat:M_PI*3/4]; 

    // Add the animation to the needle's layer. 
    [senderView.layer addAnimation:needleAnim forKey:nil]; 
} 
+0

まあ、ありがとう。私はObjective-Cの新人ですが、私は試してみます。 –

+0

もう一度友人に感謝します。私は成功しなかった。 –

+0

説明にソースコードを追加しました。あなたは正しい角度を得るためにいくつかの調整をする必要があります。 – Dondragmer

関連する問題