[英]How to cancel collectionView gestures, while touching a slider inside a cell?
I have a custom slider inside a collection view. 我在集合视图中有一个自定义滑块。 I change the value of the slider with touchesMoved.
我使用touchesMoved更改滑块的值。 the slider works great when it is not in a collection view, I only need to start sliding inside its view and then I can continue sliding while moving my finger down or up outside of its view and it still works, but when it is in a collectionView once my finger gets out of the sliders view it stops and the collection view scroll is activated.
滑块不在收藏夹视图中时效果很好,我只需要开始在其视图内滑动,然后就可以继续滑动,同时在其视图外上下移动手指仍然可以,但是当它处于一旦手指离开了滑块视图,collectionView就会停止,并且collection view滚动被激活。 How do I stop the scroll view gestures and continue with my slider?
如何停止滚动视图手势并继续使用滑块?
ok I found the answer myself. 好吧,我自己找到了答案。 here it is: I added this function in my cell class
这是:我在单元格类中添加了此功能
func getParentCollection() -> UICollectionView?
{
let collection = self.superview as? UICollectionView
return collection
}
and my slider had completions and I do this: 并且我的滑块完成了,我这样做:
self.secondaryVolumeSlider.didBeginTouch = {
self.getParentCollection()?.gestureRecognizers?.forEach({ (gesture) in
gesture.isEnabled = false
})
}
self.secondaryVolumeSlider.didEndTouching = {
self.getParentCollection()?.gestureRecognizers?.forEach({ (gesture) in
gesture.isEnabled = true
})
}
So when I start touching the slider I turn off all the gestures of the cells superview, which is the collection view and when I end sliding I turn them back on. 因此,当我开始触摸滑块时,我将关闭单元格超级视图的所有手势(即集合视图),并在结束滑动时将其重新打开。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.