iOS 7 UIImagePicker preview black screen

前端 未结 3 1653
独厮守ぢ
独厮守ぢ 2020-12-01 08:09

When i try to load camera from my code, camera preview is black. If I wait for 10-20 seconds it will show real camera preview. I found several questions and some of them sug

3条回答
  •  半阙折子戏
    2020-12-01 08:39

    This Should work for you:

        - (void)cameraViewPickerController:(UIImagePickerController *)picker
    {
        [self startCameraControllerFromViewController: picker
                                        usingDelegate: self];
    }
    
    
    - (BOOL) startCameraControllerFromViewController: (UIViewController*) controller
                                       usingDelegate: (id ) delegate {
    
        if (([UIImagePickerController isSourceTypeAvailable:
              UIImagePickerControllerSourceTypeCamera] == NO)
            || (delegate == nil)
            || (controller == nil))
            return NO;
    
    
        UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
        cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
    
        // Displays a control that allows the user to choose movie capture
        cameraUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, (NSString *) kUTTypeMovie,nil];
    
        // Hides the controls for moving & scaling pictures, or for
        // trimming movies. To instead show the controls, use YES.
        cameraUI.allowsEditing = NO;
    
        cameraUI.delegate = delegate;
    
        [controller presentViewController:cameraUI animated:YES completion:nil];
        return YES;
    }
    

提交回复
热议问题