【问题标题】:iphone development - UIRotationGestureRecognizer (Clockwise & counter Clockwise detection)?iphone 开发 - UItapGestureRecognizer(顺时针或逆时针检测)?
【发布时间】:2011-06-17 18:54:55
【问题描述】:

有没有办法检测用户所做的旋转是顺时针还是逆时针方向???

我搜索过,但找不到答案!

我的代码如下所示:

 UIGestureRecognizer *recognizer;
 recognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(spin)];
 [self.rotating addGestureRecognizer:recognizer];
 [recognizer release];

【问题讨论】:

    标签: iphone gesture


    【解决方案1】:

    rotation 属性将以弧度告诉您rotation。负值表示顺时针旋转,正值表示逆时针。

    例子:

    UIGestureRecognizer *recognizer;
    recognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(spin:)];  // <-- Note the colon after the method name
    [self.rotating addGestureRecognizer:recognizer];
    [recognizer release];
    
    - (void)spin:(UIGestureRecognizer *)gestureRecognizer {
        CGFloat rotation = gestureRecognizer.rotation;
        if (rotation < 0) {
            // clockwise
        } else {
            // counter-clockwise
        }
    }
    

    【讨论】:

    • 实际上恰恰相反。 > 0 顺时针,而
    【解决方案2】:

    Swift 版本 - 假设您已将 UIRotationGestureRecognizer 连接到 IBAction,并将 UIRotationGestureRecognizer 作为参数 recognizer 传递。你可以很容易地用以下方法测试方向:

    if recognizer.rotation < 0 {
        print("Negative rotation value means anticlockwise rotation detected")
    } else if recognizer.rotation > 0 {
        print("Positive rotation value means clockwise rotation detected")
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-26
      • 2012-12-11
      • 2012-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多