我有一个imageview,我只想点击imageview的一面。是否可以为手势设置框架?任何人都可以帮助解决方案吗?
答案 0 :(得分:3)
使用UIGestureRecognizerDelegate
,我认为您可以了解如何比较:
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if ([touch locationInView:yourview].x < somePoint.x) {
return false;
} else {
return true;
}
}
答案 1 :(得分:1)
您可以在图像视图顶部叠加视图,并将点击识别器添加到此新视图中,这样的内容将使图像的左侧可以轻触
UIView tapView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, imageView.frame.size.width/2, imageView.frame.size.height)];
[imageView addSubView:tapView]
UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleSingleTap:)];
[tapView addGestureRecognizer:singleFingerTap];
答案 2 :(得分:0)
你可以根据你的要求简单地将UIView放在你的imageView顶部,然后在那个UIView上点击手势。
您可以通过storyboard / xib或通过编程方式执行此操作。
通过编程方式,例如 - 您只想在imageView的宽度为50像素的区域内点按。为此:
UIView *vw = [[UIView alloc] initWithFrame:CGRectMake(imgView.frame.origin.x, imgView.frame.origin.y, 50, imgView.frame.size.height)];
// add gesture to view
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
tapGesture.numberOfTapsRequired = 2;
[vw addGestureRecognizer:tapGesture];
[imgView addSubview:vw];
现在处理你的双击
-(void)handleTapGesture:(UITapGestureRecognizer *)gesture
{
// handle double tap
}