2012-04-07 11 views
1

Ich habe diese Animation mit einem Hintergrundbild und 12 Bilder der Nadel in der Mitte. es läuft in Ordnung, aber jedes Mal, wenn es Bild und das Bild danach zeigt, möchte ich einfach, dass es zwischen den Bildern glatt läuft. wie kann ich das machen?wie glatte Bildanimation zu erstellen

hier ist mein aktueller Code:

- (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

Haben Sie diese Frage nicht beziehen fragte vor wenigen Stunden nur? http://stackoverflow.com/questions/10053207/how-to-animate-a-set-of-images. Dupe Konto ??? –

+0

das möchte ich nicht machen. –

+0

Ok .. Entschuldigung dafür .. :-)) –

Antwort

3

bearbeiten: Ich schlug ursprünglich UIView Animation, aber das braucht immer den kürzesten Weg, Drehen durch 90 Grad statt 270. Versuchen Sie dies, mit freundlicher Genehmigung von Can I use CGAffineTransformMakeRotation to rotate a view more than 360 degrees?

Verwenden Sie keine Sequenz von Bildern, um eine möglichst glatte Nadelanimation zu erhalten. Beginnen Sie mit einem Bild mit einer einzelnen Nadel in einer UIImageView-Ansicht, wobei die Ansicht auf das Hintergrundbild der Wählscheibe zentriert ist. Ändern Sie dann die transform-Eigenschaft der UIImageView-Ebene mit einer Transformation für die Rotation.

Sobald Sie die Geometrie ausgerichtet haben, verwenden Sie die Kernanimation, um die Transformation durch den entsprechenden Winkelbereich zu animieren.

nur zu erarbeiten, unter der Annahme, dass imgAnimation ein UIImageView ist:

- (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

gut, vielen Dank. Ich bin neu in Objective-C, aber ich werde es versuchen. –

+0

Danke nochmal Freund. Es ist mir nicht gelungen. –

+0

Ich habe der Erklärung Quellcode hinzugefügt. Sie müssen einige Anpassungen vornehmen, um die Winkel richtig einzustellen. – Dondragmer