我试图围绕其中心旋转uiview(UIPanGestureRecognizer),但由于某种原因,uiview的位置也在变化。我不明白为什么它在改变轮换时改变位置,因为我根本不试图改变位置。是不是应该旋转uiview相对于uiview的中心?
以下是:https://www.youtube.com/watch?v=5M1L2MyPdbg&feature=youtu.be
这是我的代码:
- (void)rotateHand:(UIPanGestureRecognizer *)panGesture {
if ([(UIPanGestureRecognizer*)panGesture state] == UIGestureRecognizerStateBegan) {
CGPoint touchPoint = [panGesture locationInView:[self view]];
float dx = touchPoint.x - minHandContainer.center.x;
float dy = touchPoint.y - minHandContainer.center.y;
arcTanMin = atan2(dy,dx);
startTransform = minHandContainer.transform;
}
if ([(UIPanGestureRecognizer*)panGesture state] == UIGestureRecognizerStateChanged) {
CGPoint pt = [panGesture locationInView:[self view]];
float dx = pt.x - minHandContainer.center.x;
float dy = pt.y - minHandContainer.center.y;
float ang = atan2(dy,dx);
float angleDifference = arcTanMin - ang;
minHandContainer.transform = CGAffineTransformRotate(startTransform, -angleDifference);
}
}