CABasicAnimation
으로 생성 된 회전 애니메이션을 사용하고 있습니다. UIView
을 2 초 이상 회전합니다. 하지만 UIView
을 만지면 멈출 수 있어야합니다. 애니메이션을 제거하면 뷰는 애니메이션이 시작되기 전과 같은 위치에 있습니다. 이 감동을 때,특정 지점에서 CABasicAnimation을 중지하십시오.
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"];
가 어떻게이있는 UIView
의 회전 권한을 중지 할 수 있습니다
여기 내 애니메이션 코드입니까? 터치 부분을 관리하는 방법을 알고 있지만 애니메이션의 현재 각도에서 뷰를 멈추는 방법을 알 수는 없습니다.
해결책 : 프리젠 테이션 레이어의 각도를 가져 와서 애니메이션을 제거하고 뷰의 변환을 설정하여 문제를 해결했습니다. 여기 코드는 다음과 같습니다
[self.view.layer removeAllAnimations];
CALayer* presentLayer = self.view.layer.presentationLayer;
float currentAngle = [(NSNumber *)[presentLayer valueForKeyPath:@"transform.rotation.z"] floatValue];
self.view.transform = CGAffineTransformMakeRotation(currentAngle);
? 나는 항상 각도를 얻고 있습니다 0.0000 – Hisenberg