UISwipeGestureRecognizer 手势起点

发布于 2024-09-25 12:54:41 字数 245 浏览 4 评论 0原文

是否可以从 UISwipeGestureRecognizer 获取手势起点。就像它如何可能在

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch * touch = [touches anyObject];
    gestureStartPoint = [touch locationInView:self];
}

Is it possible to get a gesture start point from a UISwipeGestureRecognizer. like how its possible in

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch * touch = [touches anyObject];
    gestureStartPoint = [touch locationInView:self];
}

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

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

发布评论

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

评论(3

—━☆沉默づ 2024-10-02 12:54:41

根据 UISwipeGestureRecognizer 文档能:

您可以通过调用 UIGestureRecognizer 方法 locationInView: 和 locationOfTouch:inView: 来确定滑动开始的位置。如果手势涉及多次触摸,前一种方法会为您提供质心;后者给出了特定触摸的位置。

PS:你真的应该先看看文档,答案在 UISwipeGestureRecognizer 的类参考中,应该不难找到。作为开发人员的一部分就是能够查找信息,Apple 有出色的文档,请使用它!

According to the UISwipeGestureRecognizer documentation you can:

You may determine the location where a swipe began by calling the UIGestureRecognizer methods locationInView: and locationOfTouch:inView:. The former method gives you the centroid if more than one touch was involved in the gesture; the latter gives the location of a particular touch.

PS: you really should first look at the documentation, the answer was in the class reference of UISwipeGestureRecognizer, shouldn't be hard to find. Part of being a developer is being able to look things up, Apple has excellent documentation, use it!

烦人精 2024-10-02 12:54:41

警告

艾米的回答完全不正确!识别器可能会生成UIGestureRecognizerStateBegan,但在滑动时UISwipeGestureRecognizer会生成UIGestureRecognizerStateEnded仅代码> 事件。

touchesBegan: 可以正常工作。问题是,如果它支持用户交互,那么它仅适用于当前视图,您需要将其传递给父视图。

WARNING

Amy's answer is totally INCORRECT! Recognizer may generate UIGestureRecognizerStateBegan but on swipe UISwipeGestureRecognizer generates UIGestureRecognizerStateEnded event only.

But touchesBegan: works instead. The problem is if it supports user interaction then it works for current view only and you need to pass it to a parent view.

会发光的星星闪亮亮i 2024-10-02 12:54:41

是的,这是可能的。参见下面的代码:

if ([recognizer state] == UIGestureRecognizerStateBegan || [recognizer state] != UIGestureRecognizerStateChanged) {
    NSLog(@"StateBegan :::::");
}

Yes, it is possible. See code below:

if ([recognizer state] == UIGestureRecognizerStateBegan || [recognizer state] != UIGestureRecognizerStateChanged) {
    NSLog(@"StateBegan :::::");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文