Objective c CGAffineTransformMakeRotation工作不正常

Objective c CGAffineTransformMakeRotation工作不正常,objective-c,ios,rotation,cgaffinetransform,Objective C,Ios,Rotation,Cgaffinetransform,我有一个游戏,你有“斑点”和“连接器” 我制作了一个UIImageView,它连接两个“斑点”…但正如您所看到的(如果图片正常),当斑点几乎彼此重叠时,就像在左边一样,它不起作用。这是我的代码…我想知道在这种情况下如何使旋转更精确 UIImageView *connector = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"RedConnector.png"]]; connector.contentMode =

我有一个游戏,你有“斑点”和“连接器”

我制作了一个UIImageView,它连接两个“斑点”…但正如您所看到的(如果图片正常),当斑点几乎彼此重叠时,就像在左边一样,它不起作用。这是我的代码…我想知道在这种情况下如何使旋转更精确

UIImageView *connector = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"RedConnector.png"]];
        connector.contentMode = UIViewContentModeScaleToFill;
        connector.hidden = NO;
        connector.alpha = 1;

        connector.frame = CGRectMake(0, 0, [self DistanceBetweenPoints:speck1.center :speck2.center], 7);
        connector.center = CGPointMake((speck1.center.x + speck2.center.x)/2, (speck1.center.y + speck2.center.y)/2);
//This is where the prob is:
        connector.transform = CGAffineTransformMakeRotation(tanh((speck2.center.y - speck1.center.y)/(speck2.center.x - speck1.center.x)) );
        [Connectors addObject:connector];
        [self.view addSubview:connector];
“点之间的距离”不是问题所在。那很好。另外,我知道中心和框架有点多余——我稍后会解决这个问题。第三,我已经确保两个斑点永远不会直接位于彼此之上(永远不会被零除)。最后,我仍然希望这些是UIImageView!!所以我可以改变图像并设置它们的动画,这样看起来就像电流从一个斑点流到另一个斑点


如果有人能告诉我如何使旋转更准确,我将不胜感激。谢谢

您应该使用
atan2(y,x)
,而不是
tanh(y/x)
。也就是说,您需要的是反正切,而不是双曲正切。

您应该使用
atan2(y,x)
,而不是
tanh(y/x)
。也就是说,你想要的是反正切,而不是双曲正切。

Wow!谢谢我以为tanh是切线,但我想那没什么意义。哇!谢谢我以为tanh是反正切的,但我想那没什么意义。