我曾尝试在的UIImagePickerController定制的摄像头,当应用外出或当我去调用Safari浏览器,到时候相机快门不开,我用下面的代码。
-(IBAction)cameraAction:(id)sender
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setValue:@"rear" forKey:@"rearcamera"];
[defaults synchronize];
NSLog(@"hai App %@",[defaults valueForKey:@"closeApp"]);
dispatch_async(dispatch_get_main_queue(), ^{
[cameraBut setSelected:NO];
self.picker = [[UIImagePickerController alloc] init];
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
self.picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
self.picker.showsCameraControls = NO;
self.picker.navigationBarHidden = YES;
self.picker.toolbarHidden = YES;
self.picker.wantsFullScreenLayout = YES;
});
}
不要在声明.h文件中的选择器。 简单的声明并在按钮操作使用和释放后的工作将完成。
-(IBAction)cameraAction:(id)sender
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setValue:@"rear" forKey:@"rearcamera"];
[defaults synchronize];
NSLog(@"hai App %@",[defaults valueForKey:@"closeApp"]);
dispatch_async(dispatch_get_main_queue(), ^{
[cameraBut setSelected:NO];
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
picker.showsCameraControls = NO;
picker.navigationBarHidden = YES;
picker.toolbarHidden = YES;
picker.wantsFullScreenLayout = YES;
[self presentViewController:picker animated:YES completion:nil];
});
}
按你的解释,我想你需要只打开相机快门,你的相机可以正常使用。
所以我建议你添加一个动画,这将模拟摄像机快门打开。
以下是一个代码,这个人是CALayer的核心动画:
CATransition *shutterAnimation = [CATransition animation];
[shutterAnimation setDelegate:self];
[shutterAnimation setDuration:0.6];
shutterAnimation.timingFunction = UIViewAnimationCurveEaseInOut;
[shutterAnimation setType:@"cameraIris"];
[shutterAnimation setValue:@"cameraIris" forKey:@"cameraIris"];
CALayer *cameraShutter = [[CALayer alloc]init];
[cameraShutter setBounds:CGRectMake(0.0, 0.0, 320.0, 425.0)];
[self.layer addSublayer:cameraShutter];
[self.layer addAnimation:shutterAnimation forKey:@"cameraIris"];
这是没有确切的解决方案,但是这是周围的途径之一。
希望这将帮助你实现你的要求。