如何使用Swift调整滑块以在Mac OSX上显示当前亮度级别?

时间:2015-12-16 22:20:23

标签: swift macos slider brightness

我创建了一个滑块,可以让我控制Mac上的亮度。我正在尝试确保滑块准确地表示当前的亮度级别。如果我通过键盘改变亮度,我希望滑块能够反映新的水平。

现在,滑块将显示当前的亮度级别,但仅在我单击滑块后。此外,我无法改变滑块的亮度。

@IBAction func brightnessSlider(sender: NSSlider) {
    verticalSlider.floatValue = getBrightnessLevel()
    setBrightnessLevel(sender.floatValue)
}

如果我删除了试图获得亮度的线条,我可以从滑块调整亮度级别,但它始终以最大值开始。

如何让滑块既可调节又始终反映亮度?

此外,here's a link如果有帮助,请填写完整的来源。

编辑: 当我使用以下代码单击菜单时,我可以让滑块显示正确的亮度,但它在打开时仍然不会更新。此外,在关闭时更新似乎是一个坏主意。

NSTimer.scheduledTimerWithTimeInterval(0.2, target: self, selector: Selector("updateBrightnessSlider"), userInfo: nil, repeats: true)

1 个答案:

答案 0 :(得分:0)

添加select field1,field2 and then check the value of field 3 if field 3 has value = 1 then select field1,field2,field3 from table 2 and join table 1 with table 2 on field1 and field1 else select field1,field2,field3 from table3 and join table1 with table2 on field1 and field1似乎有效。因此,完整的片段如下:

NSRunLoop.currentRunLoop().addTimer(timer, forMode: NSRunLoopCommonModes)