1

我已经在自定义相机中尝试了 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;



   });


}
4

2 回答 2

1

不要在 .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];

   });


}
于 2013-03-17T11:31:30.727 回答
0

根据你的解释,我猜你只需要打开相机快门,你的相机就可以正常工作了。

所以我建议你添加一个动画,模拟相机快门打开。

这是代码,这是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"];

这不是确切的解决方案,但这是解决方法之一。

希望这将帮助您实现您的要求。

于 2013-03-15T06:32:38.457 回答