gpt4 book ai didi

ios - 在 UICollectionView 上放置一个按钮并保持滚动

转载 作者:行者123 更新时间:2023-11-29 01:48:35 24 4
gpt4 key购买 nike

我有一个 UICollectionView 和一个 UIButton(在右边)。但是在按钮的框架中,collectionView 失去了它的滚动属性。

我想知道是否有任何方法可以维持这两种交互,Button 在内部触摸和 CollectionView 滚动。

最佳答案

嗯,我想出了如何做到这一点,但我使用 UITapGestureRecognizer 作为 rounak 而不是按钮建议:

    let tapGesture = UITapGestureRecognizer(target: self, action: "collectionViewDidReceiveTap:")
tapGesture.delegate = self
self.collectionView.addGestureRecognizer(tapGesture)

因为我想要一个特定的矩形是“可点击的”,所以我已经实现了 UIGestureRecognizerDelegate 协议(protocol),这段代码是这样做的:

public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
let collectionViewCurrentCell = self.collectionView.layoutAttributesForItemAtIndexPath(NSIndexPath(forItem: Int(self.currentPage), inSection: 0))
let cellFrameInSuperview = collectionView.convertRect(collectionViewCurrentCell!.frame, toView: self)

if gestureRecognizer.isKindOfClass(UITapGestureRecognizer) && CGRectContainsPoint(cellFrameInSuperview, touch.locationInView(self)) {

return false
}
return true
}

cellFrameInSuperview 应该是 TapGesture 不应该做任何事情的区域。但与 UIButton 不同的是,滚动在所有 Collection 范围内继续工作。

如果您对它的工作原理或原因有任何疑问,请发表评论。

关于ios - 在 UICollectionView 上放置一个按钮并保持滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31658678/

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