1

我在再次旋转 uiview 时遇到了一些问题。这一次,我试图以正常速度旋转的另一个 uiview 的速度旋转 uiview 1/12。但是,当我尝试完成此任务时,我试图移动较慢的 uiview 像这样移动:

第一次更新 https://www.youtube.com/watch?v=wj3nRJo5CMM&feature=youtu.be

第二次更新 https://www.youtube.com/watch?v=YLRkUzXSDtQ&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);
        arcTanHour = atan2(hourHand.center.x - minHandContainer.center.x, hourHand.center.y - minHandContainer.center.y);
        if (arcTanMin < 0) {
            arcTanMin = 2 * M_PI + arcTanMin;
        }
        if (arcTanHour < 0) {
            arcTanHour = 2 * M_PI + arcTanMin;
        }
        NSLog(@"arcTanMin %f", arcTanMin);
        startTransformMin = minHandContainer.transform;
        startTransformHour = hourHandContainer.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);
        if (ang < 0) {
            ang = 2 * M_PI + ang;
        }
        float angleDifferenceM = arcTanMin - ang;
        float angleDifferenceH = arcTanHour + angleDifferenceM * (1.0/12.0);
        NSLog(@"angleDiffM %f", angleDifferenceM);
        NSLog(@"angleDiffH %f", angleDifferenceH);
        minHandContainer.transform = CGAffineTransformRotate(startTransformMin, -angleDifferenceM);
        hourHandContainer.transform = CGAffineTransformRotate(startTransformHour, -angleDifferenceH);
    }
}
4

1 回答 1

1

您似乎使用 arcTanMin 作为分针和时针的起始参考角度。因此,当您在 x 轴上跳跃时,两者angleDifferenceMangleDifferenceH在跳跃(这就是为什么在跳跃的那一刻,时针与 y 轴的角度与分针与x 轴),但angleDifferenceH不需要进行跳转。改变这个:

float angleDifferenceH = angleDifferenceM * (1.0/12.0); 

float angleDifferenceH = arcTanHour + angleDifferenceM * (1.0/12.0);

具有适当的起始值arcTanHour

于 2014-08-16T19:39:20.140 回答