gpt4 book ai didi

swift - 来自字符串的 setTorchModeOnWithLevel

转载 作者:行者123 更新时间:2023-11-28 07:01:48 25 4
gpt4 key购买 nike

我的变量:

var torchLevel : Float = 0.0

我的切换功能:

func toggleFlash() {
let device = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
if (device.hasTorch){
device.lockForConfiguration(nil)
if (device.torchMode == AVCaptureTorchMode.On)
{
device.torchMode = AVCaptureTorchMode.Off
isTorchOn = 0
}
else
{
device.setTorchModeOnWithLevel(torchLevel, error: nil)
isTorchOn = 1
}
device.unlockForConfiguration()
}
}

更改 slider :

@IBAction func brightnessSliderAction(sender: UISlider) {
var currentBrightnessValue = Int(sender.value)
torchLevel = currentBrightnessValue
valueLabel.text = "\(torchLevel)"
}

代码错误:

torchLevel = currentBrightnessValue

错误信息:

Cannot assign a value of type "int" to a value of type "Float"

最佳答案

您需要将 torchLevel 转换为 Float。

或者让它像这样显式 float :

var torchLevel : Float = 0.0

关于swift - 来自字符串的 setTorchModeOnWithLevel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31843445/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com