swiftuicollectionviewuikituigesturerecognizeruicontrol

CollectionView doesn't scrolling through UIControl?


I have buttons inherited from UIControl in the horizontal UICollectionView. I want to add a behavior so that even when we do horizontal scrolling through buttons, my buttons don't catch touching, and first of all scrolling catches UICollectionView

-- UICollectionView
    -- UIControl (button)
    -- UIControl (button)
    -- UIControl (button)

How can this be done?


Solution

  • UICollectionView inherits from UIScrollView. So you have access to;

    open var isTracking: Bool { get } // returns YES if user has touched. may not yet have started dragging
    
    open var isDragging: Bool { get } // returns YES if user has started scrolling. this may require some time and or distance to move to initiate dragging
    
    open var isDecelerating: Bool { get } // returns YES if user isn't dragging (touch up) but scroll view is still moving
    

    I would use these checks to see if the collection isScrolling, and if so return from all button taps.