Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.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开发-UIRotationGestureRecognitor(顺时针和逆时针检测)?_Iphone_Gesture - Fatal编程技术网

iphone开发-UIRotationGestureRecognitor(顺时针和逆时针检测)?

iphone开发-UIRotationGestureRecognitor(顺时针和逆时针检测)?,iphone,gesture,Iphone,Gesture,有没有办法检测用户的旋转是顺时针方向还是逆时针方向 我搜索了一下,但找不到答案 我的代码如下所示: UIGestureRecognizer *recognizer; recognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(spin)]; [self.rotating addGestureRecognizer:recognizer]; [recognizer release

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

我搜索了一下,但找不到答案

我的代码如下所示:

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

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

例如:

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
    }
}
UIgestureRecognitor*识别器;

识别器=[[UIRotationGestureRecognitizer alloc]initWithTarget:自操作:@selector(spin:)];// Swift版本-假设您已将UIRotationGestureRecognitizer连接到iAction,并将UIRotationGestureRecognitizer作为参数
Recognitizer
传入。您可以非常轻松地使用以下各项测试方向:

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")
}
if recognizer.rotation<0{
打印(“负旋转值表示检测到逆时针旋转”)
}否则,如果recognizer.rotation>0{
打印(“正旋转值表示检测到顺时针旋转”)
}

其实情况正好相反。>0为顺时针方向,而<0为逆时针方向。