我一直在尝试实现前置闪光灯(是的,我知道它的质量非常糟糕)。我在尝试获取屏幕亮度并将白色子视图添加到正确的时间时遇到问题,因为返回的图像从未在图像中应用过闪光灯。
感谢您提供的任何帮助。
代码:
if (self.imagePicker.cameraDevice == UIImagePickerControllerCameraDeviceFront)
{
if ([self.flashButton.titleLabel.text isEqualToString:@"On"]
{
CGFloat oldBrightness = [UIScreen mainScreen].brightness;
UIWindow *window = [UIApplication sharedApplication].keyWindow;
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, window.frame.size.width, window.frame.size.height)];
[UIView animateWithDuration:1.0f
delay:0.0
options:UIViewAnimationOptionCurveLinear
animations:^
{
[self.imagePicker takePicture];
[window addSubview:view];
[[UIScreen mainScreen]setBrightness:1.0]
view.backgroundColor = [UIColor whiteColor];
view.alpha = 1.0f;
}
completion:^(BOOL finished)
{
if (finished)
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:1.0f];
view.alpha = 0.0;
[view removeFromSuperview];
[[UIScreen mainScreen]setBrightness:oldBrightness];
[UIView commitAnimations];
}
}];
}
else
{
[self.imagePicker takePicture];
}
}
答案 0 :(得分:1)
我建议将[self.imagePicker takePicture];
移到完成处理程序的开头。
动画块需要1秒才能达到全亮度,此后会立即想要拍摄照片。