在UICollectionView的空白处忽略触摸/手势

问题描述:

我在UICollectionsView下有一个地图视图(谷歌地图不是MapKit),并且希望允许地图被平移/缩放,但是因为UICollectionView被设置为占据整体屏幕截取所有触摸事件,使地图保持静态。在UICollectionView的空白处忽略触摸/手势

对于一些参考,这是我目前有和我设置UICollectionView为全屏的原因是,我可以在所有的屏幕空间内单独的单元格的位置动画。

enter image description here

我试着改写斯威夫特this answer但它抛出一个nil when unwrapping

override func point(inside point: CGPoint, with event: UIEvent?) -> Bool { 
    let indexPath: IndexPath? = self.indexPathForItem(at: point) 
    let cell: UICollectionViewCell? = (self.cellForItem(at: indexPath!)) 
    if (cell != nil) && convert(point, to: cell?.contentView).x >= 0 { 
     return true 
    } 
    return false 
} 

想通了。而不是检测触摸事件是否发生在一个单元内,我只是检查事件是否发生在某个点上,并相应地处理它。

override func point(inside point: CGPoint, with event: UIEvent?) -> Bool { 
    if point.y > cardContainerY { 
     return true 
    } 
    return false 
} 

哪里cardContainerY是真实计算关闭当前的重点卡的CGFloat(因为卡可以扩大,y空间内移动)。