Objective c 对UIImageView进行角度旋转,但它不';I don’我做不到你所期望的

Objective c 对UIImageView进行角度旋转,但它不';I don’我做不到你所期望的,objective-c,ios,cgaffinetransform,Objective C,Ios,Cgaffinetransform,我试着制造一个炮塔,它可以旋转到被触碰的位置,然后射出子弹 到目前为止没有问题,但我不明白为什么炮塔没有朝向我接触的方向 注意:我忘了告诉你它会转向,但不会转向我触摸的特定位置。 我找了这些消息来源,但他们没有帮助 这是我做旋转的代码。我错过了什么 -(void)update:(UITapGestureRecognizer *)recognizer { double dx,dy; CGPoint location = [recognizer locationInView:se

我试着制造一个炮塔,它可以旋转到被触碰的位置,然后射出子弹 到目前为止没有问题,但我不明白为什么炮塔没有朝向我接触的方向 注意:我忘了告诉你它会转向,但不会转向我触摸的特定位置。 我找了这些消息来源,但他们没有帮助

这是我做旋转的代码。我错过了什么

-(void)update:(UITapGestureRecognizer *)recognizer 
{
    double dx,dy;
    CGPoint location = [recognizer locationInView:self.view];
    turret.transform=CGAffineTransformIdentity;
    bullet.transform=CGAffineTransformIdentity;
    bullet.center=turret.center;    
    if ( location.x < 160 )
    {
        dx=turret.center.x-location.x;
        dy=turret.center.y-location.y;
        //if user touched greater than 180
    }
    else if ( location.x > 160 )
    {
        dx=location.x-turret.center.x;
        dy=location.y-turret.center.y;
        //if user touched less than 180
    }
    CGAffineTransform transform = CGAffineTransformMakeRotation((atan2(dy,dx)*180/M_PI));
    NSLog(@"%f",atan2(dy,dx)*180/M_PI);
    bullet.transform=transform; 

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1.5];
        turret.transform = transform;
    [UIView commitAnimations];  

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1.5];
        bullet.center=location;
    [UIView commitAnimations]; 
-(无效)更新:(UITapGestureRecognitor*)识别器
{
双dx,dy;
CGPoint location=[识别器位置视图:self.view];
转塔变换=CGAffineTransformity;
bullet.transform=CGAffineTransformity;
子弹中心=炮塔中心;
如果(位置x<160)
{
dx=炮塔.中心.x-位置.x;
dy=炮塔。中心。y位置。y;
//如果用户触摸超过180
}
否则,如果(位置x>160)
{
dx=位置x-炮塔中心x;
dy=位置y-炮塔中心y;
//如果用户触摸少于180
}
CGAffineTransform transform=CGAffineTransformMakeRotation((atan2(dy,dx)*180/M_-PI));
NSLog(@“%f”,atan2(dy,dx)*180/M_-PI);
bullet.transform=transform;
[UIView beginAnimations:nil上下文:NULL];
[UIView设置动画持续时间:1.5];
转塔变换=变换;
[UIView委员会];
[UIView beginAnimations:nil上下文:NULL];
[UIView设置动画持续时间:1.5];
项目符号。中心=位置;
[UIView委员会];

我相信CGAffineTransformMakeRotation使用的是弧度而不是度,所以不要将atan2(dy,dx)的输出乘以180/pi(尽管如果您希望将其记录在度中,可以在NSLog中进行记录)。

它实际上是做什么的?它是否旋转,如果是,以什么方式旋转?