[英]Custom ios camera shutter not opening?
I have tried UIImagePickerController in custom camera,when application going out or when i am going call the safari , that time camera shutter not open,i have used following code. 我已经在自定义相机中尝试过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;
});
}
Don't Declare the picker in .h file. 不要在.h文件中声明选择器。 Simple Declare and Use in Button Action and Release after work will finish. 完成工作后,简单声明并在按钮中使用和操作即可释放。
-(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];
});
}
As per your explanation, I guess you require to open camera shutter only and your camera is working perfectly. 按照您的解释,我想您只需要打开相机快门即可,相机运行良好。
So I would suggest you to add one animation, which will simulate camera shutter opening. 因此,我建议您添加一个动画,该动画将模拟相机快门的打开。
Here is the code for that, this one is Core Animation for CALayer: 这是代码,这是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"];
This is not the exact solution, but this is one of the way around. 这不是确切的解决方案,但这是解决方法之一。
Hope this will help you to achieve your requirement. 希望这可以帮助您达到要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.