2017-04-25 11 views
-1

Ich bin neu in Xamarin iOS-Entwicklung, und ich habe versucht, das Symbol um 180 Grad zu drehen, wenn angezapft.
Ich schreibe die folgende Methode für die Rotation.Drehen Sie das Symbol um 180 Grad

private void titleViewTapped(UITapGestureRecognizer tap) 
    { 
     var rotationAnimation = new CoreAnimation.CABasicAnimation(); 
     rotationAnimation.KeyPath = "transform.rotation.z"; 
     rotationAnimation.To = new NSNumber(Math.PI); 
     rotationAnimation.Duration = 0.2; 
     rotationAnimation.RemovedOnCompletion = false; 
     rotationAnimation.FillMode = CoreAnimation.CAFillMode.Forwards; 

     triangleIcon.Layer.AddAnimation(rotationAnimation, "rotationAnimation"); 
    } 

Das Programm funktioniert gut, als ich den Titel zum ersten Mal angetippt habe.
Wenn ich jedoch erneut auf den Titel tippte, wurde das Symbol um 360 Grad gedreht, nicht um 180.
Wie löst man dieses Problem?


Ich habe dieses Problem selbst gelöst.

private void titleViewTapped(UITapGestureRecognizer tap) 
    { 
     UIView.Animate(0.2, 
      () => { 
       triangleIcon.Transform = CGAffineTransform.Rotate(triangleIcon.Transform, (nfloat)Math.PI);}, 
      () => { } 
     ); 
    } 

Antwort

0

Versuchen Sie, diese

- (void) runSpinAnimationOnView:(UIView*)view duration:(CGFloat)duration rotations:(CGFloat)rotations repeat:(float)repeat 
{ 
    CABasicAnimation* rotationAnimation; 
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; 
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * rotations * duration ]; 
    rotationAnimation.duration = duration; 
    rotationAnimation.cumulative = YES; 
    rotationAnimation.repeatCount = repeat; 

    [view.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"]; 
} 
+0

Sie für den Kommentar danken. Der 'repeatCount' sollte nicht verwendet werden, da ich die Drehung nicht wiederholen möchte, nur wenn er angetippt wird –

Verwandte Themen