iDevice相机显示黑色,而不是预览 [英] iDevice camera shows black instead of preview

查看:161
本文介绍了iDevice相机显示黑色,而不是预览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发的应用程序捕获来自iDevice的相机的图像,并将其上传到Web服务。

I am developing an app that captures images from iDevice's camera and upload it to web service.

没有问题,除了设备的相机,一切正常。设备的相机驱动我的疯狂。我使用下面的代码,允许用户捕获图像。有时相机显示预览,有时不显示。而不是预览只是显示完全黑暗的屏幕上。如果我从后面切换到前面相机开始工作正常。我甚至尝试删除所有后台应用程序从设备和清除尽可能多的内存,我可以;仍然没有运气,我被卡住了。 :(

- (IBAction)addNewImage:(id)sender
{
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        // Take picture from camera
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;

        // set no to take as much pictures as user want.
        imagePicker.showsCameraControls = YES;

        // Show user the camera
        [self presentModalViewController:imagePicker
                                animated:YES];
    }
    else
    {
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentModalViewController:imagePicker
                                animated:YES];        
    }    
}

$ b b

推荐答案

我在我的应用程序中遇到了这个问题。虽然我从来没有发现问题是什么,我重写了我的代码来定义 UIIMagePickerController 类型的属性,并在getter中初始化一次。使用此属性初始化相机视图:

I had faced this issue in my app. Though I never found out the what the issue was, I rewrote my code to define a property of UIIMagePickerController type and initialize it once in the getter. Used this property to initialize the camera view :

getter:

-(UIImagePickerController *) imagePicker{
    if(!_imagePicker){
       _imagePicker = [[UIImagePickerController alloc] init];
       _imagePicker.delegate = self;
       if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
           _imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
       }
       else{
           _imagePicker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
       }  

   }
    return _imagePicker;
}


- (IBAction)addNewImage:(id)sender{
  if (self.imagePicker)
  {
      [self presentViewController:self.imagePicker animated:YES completion:^{}];
  }
}

由于某种原因,这摆脱了预览的问题有时显示黑屏

For some reason this got rid of the issue with preview sometimes showing a black screen

这篇关于iDevice相机显示黑色,而不是预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆