什么是iPhone X相机预览比例是多少?

问题描述 投票:0回答:1

我试图表明预览照相机在我看来的中心,但有一个黑色的底部。如果4/3预览的比率。此代码工作正常,除了iPhoneX所有的设备上。不幸的是我不能调试上iPhoneX(我有一个iPhone 7)。在iPhoneX预览翻译在错误的位置(右,下角)

 if !UIImagePickerController.isSourceTypeAvailable(.camera){
       //camera not available
       return
    }

    imagePicker.delegate = self
    imagePicker.sourceType = .camera
    imagePicker.showsCameraControls = false
    imagePicker.allowsEditing = false
    imagePicker.view.frame = cameraViewContainer.bounds

    //center screen camera preview
    let screenSize = UIScreen.main.bounds.size

    let cameraAspectRatio : CGFloat = 4.0 / 3.0

    if UIDevice.current.orientation.isPortrait  {
        let cameraImageHeight = screenSize.width * cameraAspectRatio
        imagePicker.cameraViewTransform = CGAffineTransform(translationX: 0, y: (screenSize.height - cameraImageHeight) / 2 )

    }
   else  if UIDevice.current.orientation.isLandscape {
         let cameraImageWidth = screenSize.height * cameraAspectRatio
         imagePicker.cameraViewTransform = CGAffineTransform(translationX: 0, y: (screenSize.width - cameraImageWidth) / 2 )

    }

    cameraViewContainer.addSubview( imagePicker.view )
swift camera
1个回答
0
投票

谷歌搜索相机的纵横比和代码没有帮助设置它,我做了什么,帮助的方式是设置cameraViewContainer在我的故事板的出口,并且设置它的约束,有它在屏幕居中,这样的在iPhone X的问题得到了解决。

© www.soinside.com 2019 - 2024. All rights reserved.