UISlider and UIScrollView

后端 未结 7 1819
猫巷女王i
猫巷女王i 2020-12-13 01:11

I have a UISlider as part of a view that is loaded into a UIScrollView with paging enabled. I\'ve noticed an unexpected behavior. If the user tries

相关标签:
7条回答
  • 2020-12-13 01:54

    most upvoted comment code in Swift 3 :)

    import Foundation
    
    class UISliderForScrollView:UISlider {
        var thumbRect:CGRect {
            let trackRect = self.trackRect(forBounds: bounds)
            return thumbRect(forBounds: bounds, trackRect: trackRect, value: value)
        }
    
        override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
            if thumbRect.contains(point) {
                return super.hitTest(point, with: event)
            } else {
                return superview?.hitTest(point, with: event)
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题