iOS 多个view添加手势,识别是哪个view的事件
1个回答
展开全部
//可以在你相应设置的响应方法里的参数里获取,我举个例子:
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
[self.view addGestureRecognizer:tap];
self.view.userInteractionEnabled = YES;
self.topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 200)];
tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
[self.topView addGestureRecognizer:tap];
self.topView.userInteractionEnabled = YES;
//手势响应方法
- (void)tapAction:(UIGestureRecognizer *)gesture
{
__weak UIView *targetView = gesture.view;
if (targetView == self.view)
{
//响应的是self.view
}
else if (targetView == self.topView)
{
//响应的是self.topView
}
}
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
[self.view addGestureRecognizer:tap];
self.view.userInteractionEnabled = YES;
self.topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 200)];
tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
[self.topView addGestureRecognizer:tap];
self.topView.userInteractionEnabled = YES;
//手势响应方法
- (void)tapAction:(UIGestureRecognizer *)gesture
{
__weak UIView *targetView = gesture.view;
if (targetView == self.view)
{
//响应的是self.view
}
else if (targetView == self.topView)
{
//响应的是self.topView
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询