0

我想“检测”旋转 - 而不是跟踪它。我需要顺时针或逆时针处理手势旋转M_PI/8,然后将图像旋转M_PI_2-M_PI_2

可以使用UIRotationGestureRecognizer吗?

4

1 回答 1

0

此代码按我的需要工作:

- (IBAction)rorationDid:(UIRotationGestureRecognizer *)recognizer
{
    static CGFloat angle = 0;
    if (recognizer.state == UIGestureRecognizerStateBegan)
        angle = recognizer.rotation;
    if (recognizer.state != UIGestureRecognizerStateEnded)
        return;

    float rotation = 0;
    if (angle - recognizer.rotation > M_PI/8)
        rotation = -M_PI_2;
    if (angle - recognizer.rotation < -M_PI/8)
        rotation = M_PI_2;

    if (rotation != 0.0)
    {
        // Let's do rotation
    }
}

更新:

这段代码:static CGFloat angle = 0;应该真的是一个@propertynot static

于 2012-09-29T09:05:48.793 回答