Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 利用目标C旋转图像_Iphone_Objective C - Fatal编程技术网

Iphone 利用目标C旋转图像

Iphone 利用目标C旋转图像,iphone,objective-c,Iphone,Objective C,我正在尝试旋转图像。我正在成功地做到这一点。问题是,当我向下单击并轻轻拖动时,图像会完全旋转到我单击的位置,然后随着我顺时针拖动图像而缓慢旋转。我关心的是为什么它会完全旋转到我拖动的地方。我希望拖动从找到的位置开始,不要旋转到我手指向下的位置,然后从那里开始 这是我的代码: - 我做错什么了吗 谢谢 我的第一个建议是,如果你的应用程序是4.0或更高版本的,那么就切换到使用UIRotateGestureRecognizer。它做了正确的事情,并为您提供了一个旋转属性。与其从触摸得到的角度创建变换,

我正在尝试旋转图像。我正在成功地做到这一点。问题是,当我向下单击并轻轻拖动时,图像会完全旋转到我单击的位置,然后随着我顺时针拖动图像而缓慢旋转。我关心的是为什么它会完全旋转到我拖动的地方。我希望拖动从找到的位置开始,不要旋转到我手指向下的位置,然后从那里开始

这是我的代码:

-

我做错什么了吗


谢谢

我的第一个建议是,如果你的应用程序是4.0或更高版本的,那么就切换到使用
UIRotateGestureRecognizer
。它做了正确的事情,并为您提供了一个
旋转属性。

与其从触摸得到的角度创建变换,不如尝试将totalRadians增加到与新角度的差值,然后从该角度创建变换

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
        NSSet *allTouches = [event allTouches];

        int len = [allTouches count]-1;

        UITouch *touch =[[allTouches allObjects] objectAtIndex:len];
        CGPoint location = [touch locationInView:[self superview]];
        float theAngle = atan2( location.y-self.center.y, location.x-self.center.x );

        totalRadians += fabs(theAngle - totalRadians);
        totalRadians = fmod(totalRadians, 2*M_PI);

        [self rotateImage:totalRadians];

    }

我还希望支持旧版本。我怀疑问题出在您的rotateImage:method中。您介意为此发布代码吗?它就在代码段的底部
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
        NSSet *allTouches = [event allTouches];

        int len = [allTouches count]-1;

        UITouch *touch =[[allTouches allObjects] objectAtIndex:len];
        CGPoint location = [touch locationInView:[self superview]];
        float theAngle = atan2( location.y-self.center.y, location.x-self.center.x );

        totalRadians += fabs(theAngle - totalRadians);
        totalRadians = fmod(totalRadians, 2*M_PI);

        [self rotateImage:totalRadians];

    }