UISlider and UIScrollView

后端 未结 7 1822
猫巷女王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:32

    I wanted to post this as a comment, but my account has no rep so I had to post a whole answer. user762391's answer including the hitTest override works perfectly. I just want to add that instead of overriding hitTest, you could instead override pointInside:withEvent: like this (keeping the thumbRect method):

    - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent * _Nullable)event {
        return CGRectContainsPoint([self thumbRect], point)
    }
    

    or in Swift:

    var thumbRect: CGRect {
        return thumbRectForBounds(bounds, trackRect: trackRectForBounds(bounds), value: value)
    }
    
    override func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool {
        return thumbRect.contains(point)
    }
    

提交回复
热议问题