将UICollectionView触摸事件传递给其父UITableViewCell [英] Pass UICollectionView touch event to its parent UITableViewCell

查看:136
本文介绍了将UICollectionView触摸事件传递给其父UITableViewCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是视图结构:

外部视图是 UITableView

UITableViewCell 内,有一个 UICollectionView 。请注意,集合视图单元格之间存在一些黑色间距。

Inside the UITableViewCell, there is a UICollectionView. And notice that there is some black spacing between the collection view cells.

当我点击UICollectionView中的间距时,我希望触摸事件传递给 UITableViewCell

When I tap the spacing in the UICollectionView, I want the touch event to pass to the UITableViewCell.

推荐答案

谷歌周围,我找到了一个解决方案。只需继承 UICollectionView 类并覆盖 hitTest:withEvent 方法。

After google around, I have found a solution.Just inherit UICollectionView class and override hitTest:withEvent method.

CustomCollectionView.h

@interface CustomCollectionView : UICollectionView

@end

CustomCollectionView.m

@implementation CustomCollectionView

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {

    UIView *hitView = [super hitTest:point withEvent:event];

    if ([hitView isKindOfClass:[self class]]) {
        // If it is class UICollectionView,just return nil.
        return nil;
    }
    // else return super implementation.
    return [super hitTest:point withEvent:event];
}

@end

这篇关于将UICollectionView触摸事件传递给其父UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆