有没有办法检测用户完成的旋转是顺时针还是逆时针直接???
我搜索了但却找不到答案!
我的代码如下所示:
UIGestureRecognizer *recognizer;
recognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(spin)];
[self.rotating addGestureRecognizer:recognizer];
[recognizer release];
答案 0 :(得分:4)
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
}
}
答案 1 :(得分:1)
快速版本-假设您已将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")
}