检测在手势识别器对象区域之外开始的轻扫



我正试图以一种非常具体的方式检测滑动,结果好坏参半。我的第一个问题是只能识别屏幕特定区域的滑动,现在这个问题已经解决了。我目前的问题是这样的:假设我在视图中有一个东西列,我让那个列的维度对应于我的手势识别器。在使用该应用程序时,必须在这些尺寸范围内开始滑动,才能被识别为滑动。相反,我需要识别滑动,即使用户开始在列的区域之外滑动。事实上,我甚至不关心它是否是一个滑动,甚至是一个点击或其他的东西是可以的,我只是想知道用户的手指是否曾经在那个列内(在这种情况下,他们肯定会从列的区域外开始滑动)。

这里是我当前的代码,其中的单词,但滑动必须在列内开始:

- (IBAction)swiperMethod:(UISwipeGestureRecognizer *)sender {
    CGPoint point = [sender locationInView:self.view];
    if(point.y < 316 && point.y > 76 && point.x < 234 && point.x > 164)
    {
        _sampleText.text=@"hi";
    }
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    UISwipeGestureRecognizer *leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swiperMethod:)];
    [leftRecognizer setDirection: UISwipeGestureRecognizerDirectionLeft];
    [[self view] addGestureRecognizer:leftRecognizer];
    // Do any additional setup after loading the view, typically from a nib.
}

谁能告诉我如何使滑动(或任何手势,我不关心它是一个明确的滑动)识别,即使用户只是拖动他/她的手指在这个区域?

谢谢!

这个方法有效!

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch * touch = [[event allTouches] anyObject];
    CGPoint point = [touch locationInView:touch.view];
    if(point.y < 316 && point.y > 76 && point.x < 234 && point.x > 164)
    {
        _sample.image = [UIImage imageNamed:@"normal.png"];
    }
    else
    {
        _star.image = [UIImage imageNamed:@"alternate.png"];
    }
}

最新更新