滑块停止时如何使滑块处于当前位置
How to make slider current position when it stopped
我正在制作计时器应用程序并且我有倒计时滑块。
我想在暂停时获取滑块的当前位置。
我尝试使用 Int(value.sender)
但我收到此错误消息:
sliderOutlet.setValue(seconds, animated: true)
Cannot invoke 'setValue' with an argument list of type '(Int, animated: Bool)'
@IBOutlet weak var sliderOutlet: UISlider!
@IBAction func slider(_ sender: UISlider)
{
seconds = Int(sender.value)
timeScreen.text = timeString(time: TimeInterval(seconds))
}
@IBAction func startButton(_ sender: UIButton)
{
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(CountdownViewController.counter), userInfo: nil, repeats: true)
sliderOutlet.isHidden = true
}
@IBAction func pauseButton(_ sender: UIButton) {
stop()
timeScreen.text = timeString(time: TimeInterval(seconds))
sliderOutlet.setValue(seconds, animated: true)
}
func stop()
{
timer.invalidate()
sliderOutlet.isHidden = false
}
我预计当我点击 pauseButton 时,sliderOutlet 会显示当前秒数的位置。
setValue(_:animated:)
方法需要 Float
,而不是 Int
。
sliderOutlet.setValue(Float(seconds), animated: true)
确保 seconds
的值介于您为滑块设置的最小值和最大值之间,默认值分别为 0.0
和 1.0
。
我正在制作计时器应用程序并且我有倒计时滑块。 我想在暂停时获取滑块的当前位置。
我尝试使用 Int(value.sender)
但我收到此错误消息:
sliderOutlet.setValue(seconds, animated: true)
Cannot invoke 'setValue' with an argument list of type '(Int, animated: Bool)'
@IBOutlet weak var sliderOutlet: UISlider!
@IBAction func slider(_ sender: UISlider)
{
seconds = Int(sender.value)
timeScreen.text = timeString(time: TimeInterval(seconds))
}
@IBAction func startButton(_ sender: UIButton)
{
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(CountdownViewController.counter), userInfo: nil, repeats: true)
sliderOutlet.isHidden = true
}
@IBAction func pauseButton(_ sender: UIButton) {
stop()
timeScreen.text = timeString(time: TimeInterval(seconds))
sliderOutlet.setValue(seconds, animated: true)
}
func stop()
{
timer.invalidate()
sliderOutlet.isHidden = false
}
我预计当我点击 pauseButton 时,sliderOutlet 会显示当前秒数的位置。
setValue(_:animated:)
方法需要 Float
,而不是 Int
。
sliderOutlet.setValue(Float(seconds), animated: true)
确保 seconds
的值介于您为滑块设置的最小值和最大值之间,默认值分别为 0.0
和 1.0
。