gpt4 book ai didi

ios - UITapGesture 仅识别 UIImageView 边框上的点击

转载 作者:行者123 更新时间:2023-11-29 00:39:43 24 4
gpt4 key购买 nike

代码如下:

这部分写在**-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath**

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageDispalyFullScreenTapped:)];
singleTap.numberOfTapsRequired = 1;
singleTap.delegate=self;
cell.imgDisplay.userInteractionEnabled = YES;
[cell.imgDisplay addGestureRecognizer:singleTap];

接下来我实现了委托(delegate),即 **UIGestureRecognizerDelegate**

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
return YES;
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return YES;
}

现在实现了点击 UIImageView 时的选择器

-(void)imageDispalyFullScreenTapped:(UITapGestureRecognizer*)gesture
{
UIView *tappedView = gesture.view;
UITableViewCell *cell=[self getSuperViewOfType:[UITableViewCell class] FromView:tappedView];
NSIndexPath *indexPath=[tblChat indexPathForCell:cell];
Sock_ModelChat *objChat=[arrDisplay objectAtIndex:indexPath.row];
if ([objChat.strUrlLocal stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].length>0) {
imgSelectedDisplay=[[Sock_DB sharedInstance] getImageForName:objChat.strUrlLocal];

ImageDisplayerViewController *imageDisplayer=[ImageDisplayerViewController sharedInstance];
imageDisplayer.delegate=self;
[self addChildViewController:imageDisplayer];
imageDisplayer.view.frame=CGRectMake(0, 0, CGRectGetWidth([UIScreen mainScreen].bounds), CGRectGetHeight([UIScreen mainScreen].bounds));
[self.view addSubview:imageDisplayer.view];
[imageDisplayer didMoveToParentViewController:self];
}
}

但问题是每当点击 ImageView 的边界侧或边缘侧时,检测到 ImageView 上的点击并触发选择器 imageDispalyFullScreenTapped。但是当点击中心或附近时中心,没有检测到水龙头,因此相关的选择器也没有触发。

我正在研究 XCode 版本 8.0 (8A218a) 和 iOS 10.0。

最佳答案

在您的情况下可能禁用了 UserInteraction

然后你可以添加像这样的手势:

let gesture:UITapGestureRecognizer = UITapGestureRecognizer.init(target:self, action:#selector(handleTap))
gesture.numberOfTapsRequired = 1
gesture.delegate = self
cell.imageView?.addGestureRecognizer(gesture)

然后在你的viewcontroller中添加下面的函数

func handleTap(sender: UITapGestureRecognizer? = nil) {}

关于ios - UITapGesture 仅识别 UIImageView 边框上的点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39804583/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com