【发布时间】:2014-08-14 13:10:50
【问题描述】:
我试图在拖动时围绕其中心旋转 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);
}
}
【问题讨论】:
-
旋转只是边界的变化。所以如果你使用自动布局,当你旋转时,子视图会改变它的边界..它可能会改变位置
标签: ios objective-c uiview rotation cgaffinetransform