我有一個在iOS 9項目中使用Swift 2的問題。將UISlider對齊到最近的數組值
我爲UISlider創建了一個數組,它正在工作。但是,滑塊不會「捕捉」到數組值,它可以位於它們之間並且是數組值之間的數字。由於我正在做一些關於價值觀的計算,所以這會搞亂我的數學。有什麼辦法可以將紗條值捕捉到最接近的數組值?
以下是我的代碼。
let fpsArray = ["23.98", "24", "25","29.97","30","50","59.94","60"]
let angleArray = ["11.25","15","22.5","30","37.5","45","60","72","75","90","108","120","144","150","172.8","180","216","270","324","360"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func fpsLabelChange(sender: UISlider) {
let currentValue = fpsArray[Int(sender.value)]
fpsLabel.text = "\(currentValue)"
}
@IBAction func angleLabelChange(sender: UISlider) {
let anglecurrentValue = angleArray[Int(sender.value)]
angleLabel.text = "\(anglecurrentValue)"
}
@IBAction func changeSpeedLabel(sender: AnyObject) {
//maths
let framespersecond = fpsSlider.value
let shutterangle = angleSlider.value
let shutterspeed = (framespersecond * 360)/(shutterangle)
speedLabel.text = "1/\(shutterspeed)"
只需使用滑塊數組索引滑動(0,1,2,3,4,5,6 ..),只是該索引處顯示元件 –
感謝您的反饋。我會怎麼做呢? –
滑塊從0到array.count-1步驟1 –