自定义ios相机快门没有打开?

时间:2013-03-14 14:09:36

标签: iphone ios5 camera uiimagepickercontroller

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



   });


}

2 个答案:

答案 0 :(得分: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];

   });


}

答案 1 :(得分: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"];

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

希望这有助于您达到您的要求。