gpt4 book ai didi

ios - 旋转 UIView(再次)

转载 作者:行者123 更新时间:2023-11-29 12:39:36 24 4
gpt4 key购买 nike

我在再次旋转 uiview 时遇到了一些问题。这一次,我试图以正常速度旋转的另一个 uiview 的 1/12 速度旋转 uiview。但是,当我尝试完成此任务时,我尝试移动较慢的 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);
}
}

最佳答案

看来您正在使用 arcTanMin 作为分针和时针的起始引用角度。因此,当您在 x 轴上跳跃时,angleDifferenceMangleDifferenceH 都在跳跃(这就是为什么在跳跃时时针的角度到 y 轴的角度与分针到 x 轴的角度相同),但是 angleDifferenceH 不需要进行跳跃。改变这个:

float angleDifferenceH = angleDifferenceM * (1.0/12.0); 

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

arcTanHour 设置适当的起始值。

关于ios - 旋转 UIView(再次),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25335040/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com