xcode UISwipeGestureRecognizer 手势起始点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3830836/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UISwipeGestureRecognizer gesture start point
提问by Rupert
Is it possible to get a gesture start point from a UISwipeGestureRecognizer. like how its possible in
是否可以从 UISwipeGestureRecognizer 获取手势起点。就像它可能在
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch * touch = [touches anyObject];
gestureStartPoint = [touch locationInView:self];
}
回答by Yannick Compernol
According to the UISwipeGestureRecognizer documentationyou can:
根据UISwipeGestureRecognizer 文档,您可以:
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.
您可以通过调用 UIGestureRecognizer 方法 locationInView: 和 locationOfTouch:inView: 来确定滑动开始的位置。如果手势中涉及多个触摸,前一种方法会为您提供质心;后者给出了特定触摸的位置。
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!
PS:你真的应该先看看文档,答案在 UISwipeGestureRecognizer 的类参考中,应该不难找到。作为开发人员的一部分是能够查找内容,Apple 有出色的文档,请使用它!
回答by Vyachaslav Gerchicov
WARNING
警告
Amy's answer is totally INCORRECT!Recognizer may generate UIGestureRecognizerStateBegan
but on swipe UISwipeGestureRecognizer
generates UIGestureRecognizerStateEnded
event only.
艾米的回答完全不正确!识别器可能会生成UIGestureRecognizerStateBegan
但仅在滑动时UISwipeGestureRecognizer
生成UIGestureRecognizerStateEnded
事件。
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.
但touchesBegan:
相反。问题是如果它支持用户交互,那么它仅适用于当前视图,您需要将其传递给父视图。
回答by Amy
Yes, it is possible. See code below:
对的,这是可能的。见下面的代码:
if ([recognizer state] == UIGestureRecognizerStateBegan || [recognizer state] != UIGestureRecognizerStateChanged) {
NSLog(@"StateBegan :::::");
}