【发布时间】: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 ???
}
}
我已经尝试返回一些东西。 self、self.superview 等......没有什么能让它正常运行(我无法上下滚动单元格)。
【问题讨论】:
标签: ios uiview uicollectionview uicollectionviewlayout hittest