ios - TapGestureRecognizer 仅在 View 调整大小后位于 View 的一部分?

标签 ios uitableview

我在我的 uitableviewcell 上添加了 UITapGestureRecognizer 就像

Mycell *outCell = (Mycell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
            if (!outCell) {
                outCell = [[Mycell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
                UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
                [outCell.bubbleView addGestureRecognizer:recognizer];
            }

outCell.bubbleView 添加到 contentview,outCell.bubbleView 根据图像大小调整大小传递给 Mycell。 当我的应用程序运行时,TapGestureRecognizer 仅在我点击单元格顶部时触发(其中高度等于默认单元格高度,单元格的其他部分不是) 对我的问题有任何答案吗?提前致谢。

最佳答案

试试下面的代码

    Mycell *outCell = (Mycell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!outCell)
    {
        outCell = [[Mycell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
        UIView *tapView = [[UIView alloc] initWithFrame:outCell.bounds];
        tapView.backgroundColor = [UIColor clearColor];
        tapView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
        [tapView addGestureRecognizer:recognizer];
        [outCell addSubview:tapView];
    }

关于ios - TapGestureRecognizer 仅在 View 调整大小后位于 View 的一部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23629702/

相关文章:

ios - 使用 arch i386 为 iPhone 模拟器编译 C 库?

ios - Swift 中泛型和 AnyObject 的区别

iphone - 使用没有代码的 iOS 模拟器,从 usb 闪存使用

swift - TableView 单元格/视觉格式语言/不断添加相同的约束?

iphone - Facebook iPhone 应用程序-启动图标效果

ios - 如何在 Swift 上单击按钮时打开 pdf 链接?

Swift UITableView reloadData() UI 行为

uitableview - parse.com 中多节 tableView 中的 cellForRowAtIndexPath 问题

json - Swift SDWebImage 中的错误

ios - 从PFUser中提取用户详细信息不起作用: key “用户名”没有数据