2016-04-20 9 views
3

Ich verwende CGAffineTransformMakeRotation, um einen Pfeil in einem Meter zu transformieren und zu drehen.Bild um mehr als 180 Grad drehen

Picture of arrow that animates inside gage

Das Problem, das ich bin vor, dass, wenn ich mehr als 180 Grad drehen Sie den Pfeil gegen den Uhrzeigersinn dreht.

Mein Ziel ist es, den Pfeil im Uhrzeigersinn im Bereich von 1 bis 280 Grad zu drehen.

Beispiel der Funktion, die den Pfeil dreht:

func rotateNeedel(value: Int){ 
    var value = 220 //for testing purpose 
    let degrees:CGFloat = CGFloat(value) 
    UIView.animateWithDuration(2.0, animations: { 
     self.ImgMaalerArrow.transform = CGAffineTransformMakeRotation((degrees * CGFloat(M_PI))/180.0) 
    })} 
+0

Schauen Sie sich diese Frage zu drehen: http://stackoverflow.com/ Fragen/9844925/uiview-unendlich-360-Grad-Drehung-Animation –

Antwort

2

können Sie CABasicAnimation verwenden, um die Ansicht Clock-Wise

func rotateNeedel(value: Double, duration: Double){ 

    let fullRotation = CABasicAnimation(keyPath: "transform.rotation") 
    fullRotation.fromValue = Double(0) 
    fullRotation.toValue = Double((value * M_PI)/180) 
    fullRotation.fillMode = kCAFillModeForwards 
    fullRotation.duration = duration 
    fullRotation.removedOnCompletion = false 

    // add animation to your view 
    self.ImgMaalerArrow.layer.addAnimation(fullRotation, forKey: "rotateViewAnimation") 
} 
+0

Erstaunlich! : D Vielen Dank – boomdrak

Verwandte Themen