gpt4 book ai didi

ios - 使用 AVCaptureDevice 时重置 UI 开关

转载 作者:行者123 更新时间:2023-11-29 13:15:51 26 4
gpt4 key购买 nike

我有一个 UISWitch 默认位置设置为 off

用户可选择将开关设置为on,我如何通过另一个按钮/操作将该开关重新关闭。

- (IBAction)switchToggled:(id)sender {

if (_toggle.on){


AVCaptureDevice *backCamera = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if ( [backCamera isTorchAvailable] && [backCamera isTorchModeSupported:AVCaptureTorchModeOn] )
{
BOOL success = [backCamera lockForConfiguration:nil];
if ( success )
{
[backCamera setTorchMode:AVCaptureTorchModeOn];
[backCamera unlockForConfiguration];
}
}
}

else {

AVCaptureDevice *backCamera = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if ( [backCamera isTorchAvailable] && [backCamera isTorchModeSupported:AVCaptureTorchModeOn] )
{
BOOL success = [backCamera lockForConfiguration:nil];
if ( success )
{
[backCamera setTorchMode:AVCaptureTorchModeOff];
[backCamera unlockForConfiguration];
}
}

}

通过 ui 按钮重置开关状态:

  - (IBAction)toggledOffSwitch:(id)sender {
_toggle.on = NO;
}

  - (IBAction)toggledOffSwitch:(id)sender {
[_toggle setOn:NO];
[_toggle setEnabled: NO];
_torch.enabled = NO;
_torch.on = NO;

}

好像没有做

更新了更多代码

最佳答案

您确定在 Xcode 中连接了您的 - (IBAction)toggledOffSwitch:(id)sender 操作吗?

关于ios - 使用 AVCaptureDevice 时重置 UI 开关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15851742/

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