在视图上限制手势 [英] limiting gesture on view

查看:97
本文介绍了在视图上限制手势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在视图上添加手势的方式

This is how I add gesture on view

- (void)_addPanGestureToView:(UIView *)view {
    UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(_handlePan:)];
    panGesture.delegate = self;
    panGesture.maximumNumberOfTouches = 1;
    panGesture.minimumNumberOfTouches = 1;
    [view addGestureRecognizer:panGesture]; 
}

一切都很完美,但手势在整体上我怎么办?像手势这样的东西仅在视图的一半内响应?

Everything is working perfectly, but gesture is on the whole view how could I do something like gesture respond only in half of view?

推荐答案

为什么不使用 CGRectContainsPoint()并检查视图中的触摸位置是否在您希望的范围内。如果不是,请忽略它:

Why not just use CGRectContainsPoint() and check if the touches location within your view is within the area you want it to be. If it isn't, ignore it:

- (void)panGestureDetected:(UIPanGestureRecognizer *)sender
{
    CGPoint location = [sender locationInView:sender.view];
    CGRect someRect = ...

    if (CGRectContainsPoint(someRect, location)) {
            // point is in specified area
    }
}

这篇关于在视图上限制手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆