我有一些代码附带一个手电筒按钮,可以打开和关闭,但它默认开始启动,这当然不应该。你们对如何轻松改变这个有什么想法吗?
if (!FrontCamera) {
if ([backCamera hasFlash]){
[backCamera lockForConfiguration:nil];
if (self.flashToggleButton.selected)
[backCamera setFlashMode:AVCaptureFlashModeOn];
else
[backCamera setFlashMode:AVCaptureFlashModeOff];
[backCamera unlockForConfiguration];
self.flashToggleButton.selected = NO;
}
else{
if ([backCamera isFlashModeSupported:AVCaptureFlashModeOff]) {
[backCamera lockForConfiguration:nil];
[backCamera setFlashMode:AVCaptureFlashModeOff];
[backCamera unlockForConfiguration];
}
[self.flashToggleButton setEnabled:NO];
}
NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:backCamera error:&error];
if (!input) {
NSLog(@"ERROR: trying to open camera: %@", error);
}
[session addInput:input];
}
if (FrontCamera) {
[self.flashToggleButton setEnabled:NO];
NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:frontCamera error:&error];
if (!input) {
NSLog(@"ERROR: trying to open camera: %@", error);
}
[session addInput:input];
}
答案 0 :(得分:0)
您使用按钮的selected
状态吗?如果是这样,请尝试:
self.flashToggleButton.selected = NO;