Ios 旋转UIView(再次)
我在再次旋转uiview时遇到一些问题。这一次,我试图将一个uiview旋转到另一个uiview的1/12的速度,我正在以正常速度旋转。但是,当我尝试完成此任务时,我尝试移动的uiview移动速度较慢,如下所示: 第一次更新 第二次更新 这是我的密码:Ios 旋转UIView(再次),ios,objective-c,uiview,cgaffinetransform,atan2,Ios,Objective C,Uiview,Cgaffinetransform,Atan2,我在再次旋转uiview时遇到一些问题。这一次,我试图将一个uiview旋转到另一个uiview的1/12的速度,我正在以正常速度旋转。但是,当我尝试完成此任务时,我尝试移动的uiview移动速度较慢,如下所示: 第一次更新 第二次更新 这是我的密码: - (void)rotateHand:(UIPanGestureRecognizer *)panGesture { if ([(UIPanGestureRecognizer*)panGesture state] == UIGestur
- (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);
}
}
-(void)rotateHand:(UIPangEstureRecognitor*)panGesture{
if([(UIPanGestureRecognizer*)panGesture状态]==UIgestureRecognizerStateStart){
CGPoint接触点=[panGesture locationInView:[自我查看]];
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;
}
如果(弧时<0){
arcTanHour=2*M_PI+arcTanMin;
}
NSLog(@“arcTanMin%f”,arcTanMin);
startTransformermmin=minHandContainer.transform;
startTransformHour=hourHandContainer.transform;
}
如果([(UIPangestureRecognitizer*)panGesture状态]==UIgestureRecognitizerStateChanged){
CGPoint pt=[panGesture locationInView:[自视图]];
float dx=pt.x-minHandContainer.center.x;
float dy=pt.y-minHandContainer.center.y;
浮点数ang=atan2(dy,dx);
if(ang<0){
ang=2*M_PI+ang;
}
浮动角度差M=arcTanMin-ang;
浮动角度差H=弧长小时+角度差M*(1.0/12.0);
NSLog(@“角度差异m%f”,角度差异m);
NSLog(@“角度差分%f”,角度差分);
minHandContainer.transform=CGAffineTransformRotate(开始TransformMin,-角度差分);
hourHandContainer.transform=CGAffineTransformRotate(startTransformHour,-角度差);
}
}
看来您正在使用arcTanMin作为分针和时针的起始参考角度。因此,当您跨x轴跳转时,angleDifferenceM
和angleDifferenceH
都在跳转(这就是为什么在跳转时,时针与y轴的角度与分针与x轴的角度相同),但angleDifferenceH
不需要跳转。更改此项:
float angleDifferenceH = angleDifferenceM * (1.0/12.0);
到
对于
arcTanHour
有一个合适的起始值,这不是很明显吗?当分针穿过x轴时,它的角度变为负值,而你联系时针角度的方式使它像过去一样跳过y轴。这不是小故障。我知道你在试图处理那个案子,但数学上有问题。我该怎么解决呢?嗯,它似乎不起作用。现在发生这种情况:。我已经更新了我的代码,我还注意到你说min使用双手的min-hand参考角度,但我这么做是因为它们都以相同的角度开始。这个改变还需要吗?对不起,我正在想办法。平移手势识别器是在整个视图上还是仅在分针上?它仅在分针上
float angleDifferenceH = arcTanHour + angleDifferenceM * (1.0/12.0);