问题
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.
-(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;
});
}
回答1:
Don't Declare the picker in .h file. 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];
});
}
回答2:
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:
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.
来源:https://stackoverflow.com/questions/15411606/custom-ios-camera-shutter-not-opening