我有一个具有多个子视图的自定义UIControl,这些子视图又具有UIButtons和UISlider。问题是UISlider有时对触摸和拖动没有反应。我尝试在大多数自定义UIViews子视图中覆盖pointInside,但是UISlider中的pointInside有时永远不会执行。这是我的代码。如何调试我的触摸/拖动被阻止的位置?
class CustomSlider: UISlider {
var thumbTouchSize : CGSize = CGSize(width: 40, height: 40)
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
var bounds: CGRect = self.bounds
bounds = bounds.insetBy(dx: -thumbTouchSize.width, dy: -thumbTouchSize.height)
let pointInside = bounds.contains(point)
NSLog("Point inside slider \(pointInside)")
return pointInside
}
override func beginTracking(_ touch: UITouch, with event: UIEvent?) -> Bool {
let thumbPercent = (value - minimumValue) / (maximumValue - minimumValue)
let thumbSize = thumbImage(for: UIControl.State.normal)!.size.height
let thumbPos = CGFloat(thumbSize) + (CGFloat(thumbPercent) * (CGFloat(bounds.size.width) - (2 * CGFloat(thumbSize))))
let touchPoint = touch.location(in: self)
return touchPoint.x >= (thumbPos - thumbTouchSize.width) && touchPoint.x <= (thumbPos + thumbTouchSize.width)
}
}