iOS develop. How to extend UIScrollView's scroll event responding area?

前端 未结 3 884
暗喜
暗喜 2020-12-17 16:34

I have a UIScrollView\'s paging enabled and set its clipToBounds = NO so that I can see outside current page.

What I want is to enable the

3条回答
  •  自闭症患者
    2020-12-17 17:12

    2019 syntax example:

    class LargerScrollArea: UICollectionView {
    
        // Example, say this is the left half of the screen, but, we wish to be
        // able to scroll on the whole width of the screen
    
        override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
    
            if isUserInteractionEnabled == false { return nil }
    
            let extraOnRight = bounds.width
            let largerBounds = bounds.inset(by:
                    UIEdgeInsets(top: 0, left: 0, bottom:0, right: -extraOnRight))
            if largerBounds.contains(point) {
                return self
            }
            else {
                return nil
            }
        }
    }
    

    (Collection view, table view, all the same.)

提交回复
热议问题