CGAffineTransformRotate:检测旋转方向

时间:2014-02-17 13:36:15

标签: ios objective-c

我要做的是:

我有一个轮子的图像和一个滚动视图。用户可以拖动滚轮向任一方向旋转。 通过检测旋转方向。我必须滚动放在滚动视图上的图像。

我在做的是:

Following this tutorial

- (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event 
{
    CGPoint touchPoint = [touch locationInView:self];
    startTouch = touchPoint; // StartTouch is static varialbel
    float dx = touchPoint.x - container.center.x;
    float dy = touchPoint.y - container.center.y;
    deltaAngle = atan2(dy,dx);
    startTransform = container.transform;
    return YES;
}



- (BOOL)continueTrackingWithTouch:(UITouch*)touch withEvent:(UIEvent*)event
 {
    CGPoint pt = [touch locationInView:self];
    float dx = pt.x  - container.center.x;
    float dy = pt.y  - container.center.y;
    float ang = atan2(dy,dx);
    float angleDifference = deltaAngle - ang;
    container.transform = CGAffineTransformRotate(startTransform, -angleDifference);
    return YES;
}

主要问题

我无法正确检测旋转方向。我使用方法 continueTrackingWithTouch 中的 angleDifference varibale来检测它。

if(angleDifference > 0){
// Positive value move in right direction.
}
else{
// Negative value move in left direction.
}

这适用于小于360 dgree的小型拖拽,但之后它无法正常工作。 任何人都可以建议我检测旋转方向的正确方法。

由于

0 个答案:

没有答案