iphone开发-UIRotationGestureRecognizer(顺时针&计数器顺时针检测)?

发布于 2024-11-15 18:14:27 字数 302 浏览 1 评论 0原文

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

我搜索过但找不到答案!

我的代码如下所示:

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

Is there a way to detect if the rotation done by the user is in clockwise or counter clockwise direct???

I searched for that but couldn't find an answer !

My code looks like this:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瞄了个咪的 2024-11-22 18:14:27

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
    }
}

the rotation property will tell you the rotation in radians. A negative value would indicate the rotation is clockwise, and a positive value indicates counter-clockwise.

Example:

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
    }
}
太阳公公是暖光 2024-11-22 18:14:27

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")
}

Swift version - imagine you've connected your UIRotationGestureRecognizer to an IBAction and are passing in the UIRotationGestureRecognizer as argument recognizer. You could very easily test direction with the following:

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")
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文