【问题标题】:UICollectionView hitTest -> normal behaviorUICollectionView hitTest -> 正常行为
【发布时间】:2014-06-18 03:48:25
【问题描述】:

我覆盖了 hitTest,效果很好。我希望它表现得好像我没有在某些条件下重写此方法,这就是问题所在。

我正在使用子类 UICollectionView 使用自定义 UICollectionViewLayout 实现在 MKMapView 上呈现单元格。我需要在UICollectionView 子类中覆盖hitTest,以便可以将触摸事件传递给mapView 并且可以滚动它。这一切都很好。

我有一个切换机制,可以在我的UICollectionViewLayout(地图)和UICollectionViewFlowLayout(将地图上的项目设置为网格格式)之间进行动画处理。这也很好用,但是当我显示流布局时,我希望用户能够像正常滚动一样滚动UICollectionView(就好像没有覆盖hitTest)。我不知道在hitTest 中返回什么以使其成为默认行为。

-(UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
    if(self.tapThrough == YES){
        NSArray *indexPaths = [self indexPathsForVisibleItems];
        for(NSIndexPath *indexPath in indexPaths){
            UICollectionViewCell *cell = [self cellForItemAtIndexPath:indexPath];
            if(CGRectContainsPoint(cell.frame, point)){
                return cell;
            }
        }
        return nil;
    } else {
        return ???
    }
}

我已经尝试返回一些东西。 selfself.superview 等......没有什么能让它正常运行(我无法上下滚动单元格)。

【问题讨论】:

    标签: ios uiview uicollectionview uicollectionviewlayout hittest


    【解决方案1】:

    如果您想要命中测试的正常行为:

    return [super hitTest:point withEvent:event];
    

    这将返回命中测试在未被覆盖时通常返回的内容。

    【讨论】:

    • 你是对的。我试过了,但同时我实现了: - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{ return NO; }
    猜你喜欢
    • 2017-07-25
    • 1970-01-01
    • 2014-03-22
    • 1970-01-01
    • 1970-01-01
    • 2013-02-21
    • 1970-01-01
    • 1970-01-01
    • 2014-10-02
    相关资源
    最近更新 更多