检测UicollectionViewCompositionallayout中正交部分上的userefent/pan/scroll
我使用构图布局在CollectionView的正交部分上使用自动滚动。我需要在用户手动滚动该部分后立即使自动滚动计时器无效。 我可以使用scrollviewDidbeGindRagging
/scrollViewWillBegIndeCelerating
,但是ScrollView委托永远不会在正交部分上调用。 如果在这种情况下有人有任何解决方法可以检测用户滚动事件,那将是有帮助的。谢谢。
I am using autoScroll on an orthogonal section of the collectionView using compositional layout. I need to invalidate the autoscroll timer as soon as the user manually scrolls the section.
I could use scrollViewDidBeginDragging
/ scrollViewWillBeginDecelerating
, but the scrollView delegates never get called on orthogonal sections.
If anyone has any workaround to detect user scroll event in this case, it will be helpful. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试了几种解决方案后,我找到了最好和最简单的解决方案。
我在UicollectionViewCell中添加了一个UipangeSturerecogniser,以收听用户PAN事件。在选择器中,我只是使计时器无效。就是这样!
另外,我们需要通过覆盖
gesturercognizer(_:syseReRecognizeSimultanealywith:)
来返回true。这就是我添加到UicollectionViewCell类中的内容:
这样,每次用户尝试滚动时,我都会使自动滚动计时器无效
After trying out several solutions, I found the best and the simplest solution.
I added a UIPanGestureRecogniser to the UICollectionViewCell to listen to user pan events. In the selector, I just invalidate the timer. That's it!
Also we need to return true by overriding
gestureRecognizer(_:shouldRecognizeSimultaneouslyWith:)
so that the vertical scroll and horizontal scrolls works properly.This is what I added to the UICollectionViewCell class:
With this, every time the user tries to scroll, I invalidate the autoScroll timer