简体   繁体   English

如何在触摸单元格内的滑块时取消collectionView手势?

[英]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.

相关问题 触摸时取消UIButton触摸 - Cancel UIButton touch while touching it 如何在重新加载 CollectionView 时防止单元格内的代码运行 - How to prevent code from inside a cell from running while CollectionView is being Reloaded 如何在CollectionView上滑动最后一个单元格的同时滚动到第一个单元格? - How to scroll to first cell, while swiping the last cell on CollectionView? tableview单元格内的Collectionview不会增加collectionView的高度 - Collectionview inside tableview cell not increasing height of collectionView collectionView单元格中的按钮选择器 - selector for button inside collectionView cell collectionview在tableview单元格内重复 - collectionview are repeating inside a tableview cell UITableView内的CollectionView单元重复 - CollectionView cell inside UITableView is repeating 如何刷新CollectionView中单元格内的按钮? - How can i refresh buttons inside a cell in CollectionView? 如何使集合视图响应它自己视图之外的平移手势 - How to make a collectionview respond to pan gestures outside of it's own view 当点击collectionView单元格内的按钮时,如何获取表格视图行并从位于tableViewCell内的collectionView推送到viewController - how to get table view row and push to viewController from collectionView that's inside a tableViewCell when tapped button inside collectionView cell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM