将UISwipeGestureRecognizer限制为仅检测IUImageView区域内的滑动

时间:2013-05-19 07:50:15

标签: ios xcode uiimageview uigesturerecognizer

我目前正在使用以下代码检测我的应用中的滑动手势:

- (IBAction)swiperMethod:(UISwipeGestureRecognizer *)sender {
    _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.
}

但是,我想将滑动识别限制为UImageView定义的部分屏幕。有一个简单的方法吗?感谢。

1 个答案:

答案 0 :(得分:1)

如果您知道UIImageView的位置,您可以测试手势是否在该区域内:

- (BOOL)pointInside:(CGPoint)point{

    return (point.y < imageViewBottom && point.y > imageViewTop && point.x < imageViewRight && point.x > imageViewLeft);
}

如果手势在UIImageview之外,则忽略它。