简体   繁体   English

UICollectionView:补充视图阻止项目选择

[英]UICollectionView: supplementary view blocks items selection

I'm implementing calendar layout for UICollectionView . 我正在为UICollectionView实现日历布局。 There are 'event' cells and 'current time' supplementary view. 有“事件”单元格和“当前时间”补充视图。 According to design I display 'current time' view above events. 根据设计,我在事件上方显示“当前时间”视图。

The problem is that if user touches 'current time' view an 'event' cell can't be selected. 问题在于,如果用户触摸“当前时间”视图,则无法选择“事件”单元格。

I tried to override - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event method of supplementary view and return nil, bit it never called. 我试图重写- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event补充视图的- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event方法并返回nil,它从未调用过。 userInteractionEnabled equals to YES for this supplementary view. 此补充视图的userInteractionEnabled等于YES

Any ideas how can I transfer touches from supplementary view to UICollectionView cells? 有什么想法可以将触摸从补充视图转移到UICollectionView单元格吗?

I don't completely understand what you are trying to achieve and maybe a bit of code would help but my guess is that you want to tap something in a header view and select today's events? 我不完全理解您要实现的目标,可能需要一些代码会有所帮助,但我想您想在标题视图中点击某些内容并选择今天的活动吗?

If so you need to capture the touch, maybe with a UIButton, in the supplementary view. 如果是这样,则需要在补充视图中捕获触摸,也许需要使用UIButton。 Then you want to call 那你想打电话

[_collectionView selectItemAtIndexPath:myIndexPath animated:YES scrollPosition:position];

If you are saying that touching the supplementary view blocks touches on the collection view I would check the frames as you may have something on top of something else and not realise. 如果您说触摸补充视图块会触及集合视图,那么我会检查框架,因为您可能有其他东西在上面,而没有意识到。 Maybe try and make the backgrounds of elements red etc to see what is where. 也许尝试将元素的背景设为红色等,以查看位置在哪里。

I think that the best way is to optimise you responder chain, look at Event Delivery: The Responder Chain 我认为最好的方法是优化您的响应者链,请参阅事件交付:响应者链

But if you are trying to do something really irregular in addition you always can handle user touches explicitly by some dedicated view. 但是,如果您尝试做一些实际上不规则的操作,那么您始终可以通过某些专用视图显式处理用户触摸。 If you have got the coordinates of user touch then use UICollectionView method to get the index path of affected cell: 如果您已获得用户触摸的坐标,请使用UICollectionView方法获取受影响单元格的索引路径:

- (NSIndexPath *)indexPathForItemAtPoint:(CGPoint)point

Do not forget to convert the coordinates to the appropriate coordinate system using UIView method: 不要忘记使用UIView方法将坐标转换为适当的坐标系:

- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM