问题描述
我有一个自定义UiSlider
,它将覆盖trackRect
函数,以定义更细的音轨。不幸的是,它在滑块框架内将整个滑块向上移动,而现在显示拇指的位置是另一个地方,UiSlider
具有拇指控制。因此,移动拇指几乎是不可能的。仅当在显示拇指的下方拖动时才起作用。
那是哪里来的?
import UIKit
@IBDesignable
class MySlider: UiSlider {
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
self.commonInit()
}
override init(frame: CGRect) {
super.init(frame: frame)
self.commonInit()
}
override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
commonInit()
}
func commonInit(){
minimumTrackTintColor = UIColor.label
maximumTrackTintColor = UIColor.label
}
// When this is added,the whole slider incl. thumb is moved up,and the control doesn't work properly when moving the thumb (as it is too high)
override func trackRect(forBounds bounds: CGRect) -> CGRect {
let customBounds = CGRect(origin: bounds.origin,size: CGSize(width: bounds.size.width,height: 2))
return customBounds
}
}
原始UiSlider
:
自定义MySlider
:
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)