Swift自定义UISlider的圆点,UISlider手势与侧滑返回手势冲突

import UIKit

class CustomSlider: UISlider {
    
    init() {
        super.init(frame: CGRect())
        self.minimumValue = 0
        self.maximumValue = 100
        self.value = 0
        self.minimumTrackTintColor = .orange
        self.maximumTrackTintColor = .green
        //自定义圆点图标
        self.setThumbImage(R.image.icon_slider(), for: .normal)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //修改slider的位置和大小
    override func trackRect(forBounds bounds: CGRect) -> CGRect {
        return CGRect(x: 0, y: 14, width: self.frame.size.width, height: 6)
    }
    //修改圆点图标的位置和触摸区域的大小
    override func thumbRect(forBounds bounds: CGRect, trackRect rect: CGRect, value: Float) -> CGRect {
        var trect = rect
        trect.origin.x -= 5
        trect.size.width += 10
        var srect = super.thumbRect(forBounds: bounds, trackRect: trect, value: value)
        srect.origin.y += 2
        return srect
    }
    //处理手势冲突
    override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        return false
    }
    
}

你可能感兴趣的:(Swift)