iPad uiimagepickercontroller 仅前置摄像头

Posted

技术标签:

【中文标题】iPad uiimagepickercontroller 仅前置摄像头【英文标题】:iPad uiimagepickercontroller only front camera 【发布时间】:2013-07-08 05:36:03 【问题描述】:

我有一个 iPad 应用,应该只使用设备上的前置摄像头,

问题是我用前置摄像头拍完第一张照片后,如果用户选择重拍,则使用后置摄像头,如果再次重拍则使用正确的前置摄像头,

每次点击拍照时,我都会释放 imagePicker,然后弹出显示我的相机预览和图像的弹出窗口。

- (void)setUpImagePicker

    //poner photo picker en pop up!
    BOOL hasCamera = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];

    picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = hasCamera ? UIImagePickerControllerSourceTypeCamera :    UIImagePickerControllerSourceTypePhotoLibrary; 
    picker.cameraDevice = UIImagePickerControllerCameraDeviceFront; 
    [picker setShowsCameraControls:FALSE];
    CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, 0.0);
    picker.cameraViewTransform = translate;
    CGAffineTransform scale = CGAffineTransformScale(translate, 1, 1);
    picker.cameraViewTransform = scale;

    self.companyPopOverController = [[[UIPopoverController alloc] initWithContentViewController:picker] autorelease];
    self.companyPopOverController.passthroughViews=[NSArray arrayWithObject:self.view]; 
    [self createTimer];

- (NSTimer*)createTimer 

    // create timer on run loop
    return [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(timerTicked:) userInfo:nil repeats:NO];


- (void)timerTicked:(NSTimer*)timer 

    [self.companyPopOverController presentPopoverFromRect:CGRectMake(622, 534, 10, 10) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];

- (void)takePicButtonPressed:(id)sender

    NSLog(@"takePicButtonPressed");

    if (!self.retakePic) 
        NSLog(@"retake no");
        self.retakePic = YES;
        self.imageTaken = YES;

        [self.takePicButton setImage:[UIImage imageNamed:@"takePicButton_Re"] forState:UIControlStateNormal];
        [picker takePicture];

        return;
    else 
        NSLog(@"retake is yes");
        self.retakePic = NO;
        self.imageTaken = NO;

        picker = nil;
        [picker release];
        self.companyPopOverController = nil;
        [self.companyPopOverController release];
          [self setUpImagePicker];

        //button image, take
        [self.takePicButton setImage:[UIImage imageNamed:@"takePicButton"] forState:UIControlStateNormal];

        return;
    


那么如何确保我的应用只使用前置摄像头?

谢谢!

【问题讨论】:

【参考方案1】:

这是一种变通方法,但是因为没有代表您正在寻找的内容,所以这会解决问题。

在 ViewDidLoad 中从 PickerController 注册通知(在这种情况下,因为您实现了自己的控件,您可能必须设置自己的通知)

   [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(retakeImage:)
                                             name:@"_UIImagePickerControllerUserDidRejectItem" object:nil];

然后,当用户选择重新拍摄照片时,请重新激活选择器以使用前置摄像头。

  - (void)retakeImage:(NSNotification *)notification
  
      self.pickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;
  

希望这会有所帮助!

【讨论】:

以上是关于iPad uiimagepickercontroller 仅前置摄像头的主要内容,如果未能解决你的问题,请参考以下文章

Monotouch - 带有 iPad 应用的 UIImagePickerController

iPad 问题中未显示 UIImagePickerController

iPhone/iPad 相机覆盖视图自动旋转问题 UIImagePickerController

UIImagePickerController 不尊重 iPad 上的视频最长持续时间

UIImagePickerController 在 iPad 而不是 iPhone 上崩溃应用程序

iPad:在横向呈现 UIImagePickerController 会在关闭时旋转我的其他视图控制器