- (BOOL)setTorchModeOnWithLevel:(float)torchLevel error:(NSError **)outError
Does what you want. However, from what I see, it is updated only at certain intervals (~ 0.2).
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; [device lockForConfiguration:nil]; [device setTorchModeOnWithLevel:slider.value error:NULL]; [device unlockForConfiguration];
Edit - full example:
Here is the UISlider. You need to add an IBAction output to the slider or add a target programmatically (e.g. me):
UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(20.0f, 20.0f, 280.0f, 40.0f)]; slider.maximumValue = 1.0f; slider.minimumValue = 0.0f; [slider setContinuous:YES]; [slider addTarget:self action:@selector(sliderDidChange:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:slider];
Then, in response to the change in the slider:
- (void)sliderDidChange:(UISlider *)slider { AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; [device lockForConfiguration:nil]; [device setTorchModeOnWithLevel:slider.value error:NULL]; [device unlockForConfiguration]; }
Daniel Amitay
source share