我再次遇到一些旋转uiview的问题。这一次,我试图旋转一个uiview 1/12的速度,我正在以正常速度旋转另一个uiview。然而,当我试图完成这项任务时,我试图移动的uiview移动速度会变得更慢,如下所示:
第一次更新https://www.youtube.com/watch?v=wj3nRJo5CMM&feature=youtu.be
第2次更新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);
}
}
发布于 2014-08-16 19:39:20
看起来您正在使用arcTanMin作为分针和时针的起始参考角。因此,当您跨越x轴进行跳跃时,angleDifferenceM
和angleDifferenceH
都在进行跳跃(这就是为什么在跳跃的瞬间,时针与y轴的夹角与分针与x轴的夹角相同),但angleDifferenceH
不需要进行跳跃。更改此设置:
float angleDifferenceH = angleDifferenceM * (1.0/12.0);
至
float angleDifferenceH = arcTanHour + angleDifferenceM * (1.0/12.0);
具有适当的arcTanHour
起始值。
https://stackoverflow.com/questions/25335040
复制