UIPickerController留下黑色底栏

时间:2016-01-04 13:59:38

标签: ios iphone uiimagepickercontroller

我使用以下代码显示UIPickerController及其叠加视图:

-(void) viewDidLoad{
    self.overlayView = [[OverlayViewController alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.overlayView.delegate = self;
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        imagePickerController = [[UIImagePickerController alloc] init];
        imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
        imagePickerController.modalPresentationStyle = UIModalPresentationFullScreen;
        imagePickerController.cameraOverlayView.frame=self.view.frame;
        imagePickerController.showsCameraControls = NO;
        imagePickerController.navigationBarHidden = YES;
        imagePickerController.toolbarHidden = YES;
    //imagePickerController.cameraViewTransform = CGAffineTransformScale(imagePickerController.cameraViewTransform, 1.0, 1.3);
        imagePickerController.delegate = self.overlayView;
        // as a delegate we will be notified when pictures are taken and when to dismiss the image picker

        [self.view addSubview:imagePickerController.view];
        imagePickerController.cameraOverlayView =self.overlayView.view;
    } else {
        [self.view addSubview:self.overlayView.view];

    }
 }

然而,当iPhone保持纵向时,屏幕底部会显示黑条。您可能会在附加的屏幕截图中看到景观中没有条形图。如何解决?Portrait Landscape

3 个答案:

答案 0 :(得分:0)

我认为这个问题:How to get the custom overlay for UIImagePicker camera to be full screen in iOS 7?是同一个问题,你可以在那里找到答案。

答案 1 :(得分:0)

我在故事板中插入viewController后按照线程中的建议实现了它:

-(void) viewDidLoad{
     self.overlayView = [[OverlayViewController alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
     self.overlayView.delegate = self;
     if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
     {
         imagePickerController = [[UIImagePickerController alloc] init];
         imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
         imagePickerController.modalPresentationStyle = UIModalPresentationFullScreen;
         imagePickerController.cameraOverlayView.frame=self.view.frame;
         imagePickerController.showsCameraControls = NO;
         imagePickerController.navigationBarHidden = YES;
         imagePickerController.toolbarHidden = YES;

         //imagePickerController.cameraViewTransform = CGAffineTransformScale(imagePickerController.cameraViewTransform, 1.0, 1.3);
         imagePickerController.delegate = self.overlayView;
         // as a delegate we will be notified when pictures are taken and when to dismiss the image picker
         self.overlayView=[self.storyboard instantiateViewControllerWithIdentifier:@"OverlayViewController"];
         [self.view addSubview:imagePickerController.view];
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showSlider) name:@"showSlider" object:nil];
         imagePickerController.cameraOverlayView =self.overlayView.view;
         CGSize screenSize = [[UIScreen mainScreen] bounds].size;
         float cameraAspectRatio = 4.0 / 4.0; //! Note: 4.0 and 4.0 works
         float imageWidth = floorf(screenSize.width * cameraAspectRatio);
         float scale = ceilf((screenSize.height / imageWidth) * 10.0) / 10.0;
         self.imagePickerController.cameraViewTransform = CGAffineTransformMakeScale(scale, scale);
      } else {
         [self.view addSubview:self.overlayView.view]; 
    }
 }

事实上,将cameraAspectRatio调整为4.0,4.0之后,这个工作正常。然而,当在横向上显示应用程序时,图像和控件会反转。这是我的门把手显示的方式。此外,当我向上指向iPhone时,图像会向侧面移动而反之亦然。Rotated image 可以修复还是我需要放弃景观选项?

答案 2 :(得分:0)

对于任何可以使用它的人来说,他就是 swift 中的代码:

@IBAction func takePhoto(_ sender: Any) {
    imagePicker =  UIImagePickerController()
    imagePicker.delegate = self
    imagePicker.sourceType = .camera
    imagePicker.cameraCaptureMode = .photo
    imagePicker.cameraDevice = .front
    imagePicker.cameraOverlayView?.frame = view.frame
    imagePicker.showsCameraControls = false
    imagePicker.isNavigationBarHidden = true
    imagePicker.isToolbarHidden = true
    let screenSize = UIScreen.main.bounds.size
    let cameraAspectRatio: Float = 4.0 / 4.0
    let imageWidth = floorf(Float(screenSize.width * CGFloat(cameraAspectRatio)))
    let scale = ((screenSize.height / CGFloat(imageWidth)) * 10.0).rounded() / 10.0;
    imagePicker.cameraViewTransform = CGAffineTransform(scaleX: CGFloat(scale), y: CGFloat(scale))
    

    present(imagePicker, animated: false, completion: nil)
}

在我的情况下,我通过按钮调用此屏幕。