旋转UIView导致它改变位置

时间:2014-08-14 13:10:50

标签: ios objective-c uiview rotation cgaffinetransform

我试图围绕其中心旋转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);
    }
}

1 个答案:

答案 0 :(得分:1)

可能会发生一些事情。首先,如果你有自动布局,它可能会对你进行旋转做一些奇怪的事情,比如在this线程中讨论过,在旋转过程中试图保持UIView和设备两侧之间的边界。尝试将其关闭并测试当前是否打开。

如果情况并非如此,您可能需要查看this主题。