I'm trying to rotate a uiview around its center on drag (UIPanGestureRecognizer), but for some reason the uiview's position is also changing. I don't understand why its changing position when it changes rotation because I don't attempt to change position at all. Isn't rotation supposed to rotate the uiview relative to the center of the uiview?
Here is what is looks like: https://www.youtube.com/watch?v=5M1L2MyPdbg&feature=youtu.be
Here is my code:
- (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);
}
}