gpt4 book ai didi

ios - UICollectionView 滚动到它的 View 之外

转载 作者:搜寻专家 更新时间:2023-11-01 07:14:48 25 4
gpt4 key购买 nike

我想在外部 View 滚动时滚动我的收藏 View ...我找到了这个答案:How to make a collectionview respond to pan gestures outside of it's own view但它对我不起作用。

我的 viewController 中的代码

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
pager.touchesBegan(touches, with: event)
}

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesMoved(touches, with: event)
pager.touchesMoved(touches, with: event)
}

override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event)
pager.touchesCancelled(touches, with: event)
}

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
pager.touchesEnded(touches, with: event)
}

override func viewDidLoad() {
super.viewDidLoad()
pager = Carousel(withFrame: self.view.bounds, andInsets: 5)
pager.dataSource = self
pager.translatesAutoresizingMaskIntoConstraints = false
pager.register(MyCollectionView.self, forCellWithReuseIdentifier: "Cell")
self.swipeView.addSubview(pager)
pager.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 1).isActive = true
pager.heightAnchor.constraint(equalToConstant: 300).isActive = true
pager.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
pager.topAnchor.constraint(equalTo: view.topAnchor, constant: 50).isActive = true
}

请帮忙,谢谢

最佳答案

在您的情况下,您需要告诉您的 View Carousel 触摸在 View 内

您需要覆盖hitTest 函数并返回自身carousel

class TouchCarousel: Carousel {
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
return true
}
}

然后使用你创建的类<​​/p>

pager = TouchCarousel(withFrame: self.view.bounds, andInsets: 5)

关于ios - UICollectionView 滚动到它的 View 之外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42763685/

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