gpt4 book ai didi

ios - 使 UICollectionViewCell 的一部分不可点击

转载 作者:行者123 更新时间:2023-11-29 12:49:26 26 4
gpt4 key购买 nike

基本上我想要做的是在 UICollectionView 中有一个单元格,它的一部分将响应点击,而另一部分则不会。这个单元格将是一个普通的单元格,在点击时展开,在展开的区域显示一个不响应点击的 subview 。

我考虑过扩展单元格并在上方 添加一个 subview ,这将无法点击。但我认为这是一种“糟糕”的实现方式。

有没有最好的方法?

这就是我想要做的:

enter image description here

感谢任何帮助,谢谢!

最佳答案

您需要子类 UICollectionViewCell,然后覆盖 hitTest:withEvent 而不是 pointInside:withEvent,在 hitTest:withEvent: 你应该定义targetRect,然后检查用户点击的点是否在targetRect内。

这是在我的 tableViewCell 上运行的代码(类似于 collectionViewCell)。

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
CGRect targetRect = CGRectMake(0, 0, CGRectGetWidth(self.bounds), 20);
if (CGRectContainsPoint(targetRect, point)) {
return nil;
} else {
return [super hitTest:point withEvent:event];
}
}

关于ios - 使 UICollectionViewCell 的一部分不可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22773251/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com