如何使用UIRotationGestureRecognizer进行延迟旋转?

时间:2012-09-29 08:06:07

标签: ios cocoa-touch uigesturerecognizer

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

是否可以使用UIRotationGestureRecognizer

1 个答案:

答案 0 :(得分: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;应该是@property而不是static