作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的变量:
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/
我的变量: var torchLevel : Float = 0.0 我的切换功能: func toggleFlash() { let device = AVCaptureDevice
我正在使用这种方法打开手电筒: - (void)checkTorch { for (AVCaptureDevice *device in [AVCaptureDevice devices])
如果设备不支持 LED 调光,我正尝试关闭手电筒应用中的图像。 NSError* outError; BOOL success = [device setTorchModeOnWi
我是一名优秀的程序员,十分优秀!