Ich verwende eine Rotationsanimation erstellt mit CABasicAnimation
. Es dreht sich ein UIView
über 2 Sekunden. Aber ich muss in der Lage sein, es zu stoppen, wenn die UIView
berührt wird. Wenn ich die Animation entferne, befindet sich die Ansicht an derselben Position wie vor dem Start der Animation.Stop CABasicAnimation an bestimmten Punkt
Hier ist meine Animation Code:
float duration = 2.0;
float rotationAngle = rotationDirection * ang * speed * duration;
//rotationAngle = 3*(2*M_PI);//(double)rotationAngle % (double)(2*M_PI) ;
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: rotationAngle ];
rotationAnimation.duration = duration;
rotationAnimation.cumulative = YES;
rotationAnimation.removedOnCompletion = NO;
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
rotationAnimation.fillMode = kCAFillModeForwards;
rotationAnimation.delegate = self;
[self.view.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
Wie kann ich die UIView
‚s Drehung rechts halten, wo es ist, wenn es berührt wird? Ich weiß, wie man den Berührungsteil verwaltet, aber ich kann nicht herausfinden, wie man die Ansicht im gegenwärtigen Winkel der Animation stoppt.
Lösung: Ich löste das Problem, indem ich den Winkel der Darstellungsschicht erhielt, die Animation entfernend und die Transformation der Ansicht einstellte. Hier ist der Code:
[self.view.layer removeAllAnimations];
CALayer* presentLayer = self.view.layer.presentationLayer;
float currentAngle = [(NSNumber *)[presentLayer valueForKeyPath:@"transform.rotation.z"] floatValue];
self.view.transform = CGAffineTransformMakeRotation(currentAngle);
wo haben Sie die obige Lösung gegeben ?? Ich bekomme immer Winkel 0,0000 – Hisenberg