我有一个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;
}
似乎没有这样做
更新了更多代码