ios - 停止时如何使滑块处于当前位置
问题描述
我正在制作计时器应用程序,并且我有倒计时滑块。我想在暂停时获取滑块的当前位置。
我尝试使用Int(value.sender)
,但出现以下错误消息:
sliderOutlet.setValue(seconds, animated: true)
无法使用类型为“(Int,动画:Bool)”的参数列表调用“setValue”
@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
。
推荐阅读
- ios - 动画子视图 AutoLayout 约束更改
- loops - 获取一个循环以显示从 2048 到 1 的 2 的所有幂,显示 2048、1024、512、...、1
- node.js - Node.js 中的同步 api 调用
- powershell - “-split” - 从“-stream”输出?
- glassfish-4 - 启动 GlassFish 4.0 时无法找到或加载主类 Files.Microsoft
- oracle - 计算两个字段之间的日期
- mysql - 在 MySQL 中转换日期
- android - 我可以根据我的应用主题为我的应用中的所有 AppBarLayout 设置样式吗?
- sql-server - 尝试在 SSAS 多维数据集中使用连接,但它们似乎不起作用
- javascript - 在 javascript + D3/mapbox 中可视化大量数据的高效/高性能方式