Tôi đang sử dụng hoạt ảnh xoay được tạo với CABasicAnimation
. Nó quay UIView
trong 2 giây. Nhưng tôi cần để có thể ngăn chặn nó khi chạm vào UIView
. Nếu tôi xóa hoạt ảnh thì chế độ xem ở cùng vị trí như trước khi hoạt ảnh bắt đầu.Dừng CABasicAnimation tại điểm cụ thể
Đây là mã hoạt hình của tôi:
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"];
Làm thế nào tôi có thể ngừng 's UIView
luân chuyển ngay nó ở đâu, khi nó chạm vào? Tôi biết làm thế nào để quản lý một phần cảm ứng, nhưng tôi không thể tìm ra cách để ngăn chặn quan điểm ở góc hiện tại của hoạt hình.
Giải pháp: Tôi giải quyết được vấn đề bằng cách lấy góc của lớp trình bày, xóa hoạt ảnh và đặt biến đổi của chế độ xem. Dưới đây là các mã:
[self.view.layer removeAllAnimations];
CALayer* presentLayer = self.view.layer.presentationLayer;
float currentAngle = [(NSNumber *)[presentLayer valueForKeyPath:@"transform.rotation.z"] floatValue];
self.view.transform = CGAffineTransformMakeRotation(currentAngle);
bạn đã đặt giải pháp ở trên ở đâu? Tôi luôn nhận được góc 0.0000 – Hisenberg