前置摄像头上的操作表没有响应

时间:2013-03-13 15:07:55

标签: ios objective-c ipad

我已经设置了一个动作表,它可以在拍照时返回3个选项(拍照,从画廊中选择并取消),前置摄像头出现并完美拍摄照片,但问题是当我再拍一张照片时,它不向我展示面对相机的frotn,它向我展示了后置摄像头。 这是代码:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{   
    CustomImagePickerController *imagePicker = [[CustomImagePickerController alloc] init];
    [imagePicker setDelegate:self];
    [imagePicker setAllowsEditing:YES];

    if(buttonIndex == 0) {
        [imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
        [imagePicker setCameraDevice:UIImagePickerControllerCameraDeviceFront];
    } else if(buttonIndex == 1) {
        [imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
    }

我在代码中有更多内容,但主要操作设置在那里。

有什么不对吗? 感谢

2 个答案:

答案 0 :(得分:1)

可能发生这种情况的原因是,当您第一次启动相机时,后台中的AVCaptureSession可能会在解除控制器后继续运行。因此,当你下次出现它时,它试图添加前置摄像头但它很忙,所以它转到下一个可用(后置摄像头),自动中断(从而释放前一个)等等。如果您使用的是ARC,那么最好使用imagePicker作为您正在使用它的类的属性。

或每次检查相机设备

if(buttonIndex == 0)
    {
        if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
        {
            imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
            [imagePicker setCameraDevice:UIImagePickerControllerCameraDeviceFront];
        }

    }

答案 1 :(得分:0)

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    CustomImagePickerController *imagePicker = [[CustomImagePickerController alloc] init];
[imagePicker setDelegate:self];
[imagePicker setAllowsEditing:YES];

    if(buttonIndex == 0)
    {
        if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
        {
            imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
            [imagePicker setCameraDevice:UIImagePickerControllerCameraDeviceFront];
        }
        else
        {
            imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
            [imagePicker setCameraDevice:UIImagePickerControllerCameraDeviceFront];
        }

         [self presentViewController:imagePicker animated:YES completion:nil ];

    }
    else if (buttonIndex==1)
    {
        imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
        [self presentViewController:imagePicker animated:YES completion:nil ];

    }
}