我在 UICollectionsView
下有一个 map View (Google Maps 而不是 MapKit),我想允许平移/缩放 map ,但是由于 UICollectionView
设置为占据整个屏幕,它会拦截所有触摸事件,使 map 保持静止。
作为引用,这就是我目前所拥有的,我将 UICollectionView
设置为全屏的原因是这样我就可以在所有屏幕空间内分别为单元格的位置设置动画。
我试过重写 this answer在 Swift 中,但它在展开时抛出一个 nil
:
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
}
最佳答案
想通了。我没有检测触摸事件是否发生在单元格内,而是检查事件是否发生在某个 y
点之后并进行相应处理。
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
if point.y > cardContainerY {
return true
}
return false
}
cardContainerY
是一个 CGFloat
,它是根据当前聚焦的卡片计算出来的(因为卡片可以展开,在 y
空间内移动).
关于ios - 忽略 UICollectionView 空白处的触摸/手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42603089/