首页 > 解决方案 > iPhone 12 Pro 的 UIImagePickerController 的相机视图在它上面有很大的差距,其他手机没有这个差距

问题描述

我正在使用 UIImagePickerController 的相机。这是一些简化的代码来展示它

let imagePickerController = UIImagePickerController()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        imagePickerController.sourceType = .camera
        imagePickerController.showsCameraControls = false
        imagePickerController.cameraCaptureMode = .photo
        
//        if traitCollection.horizontalSizeClass == .compact  || traitCollection.verticalSizeClass == .compact {
//            let screenSize = UIScreen.main.bounds.size
//            let previewRatio: CGFloat = 4 / 3
//            let previewHeight = screenSize.width * previewRatio
//            let offset = (screenSize.height - previewHeight) / 2
//            imagePickerController.cameraViewTransform = CGAffineTransform(translationX: 0, y: offset)
//        }
        
        showImagePickerController()
    }
    
    private func showImagePickerController() {
        addChild(imagePickerController)
        view.addSubview(imagePickerController.view)
        imagePickerController.didMove(toParent: self)
    }

到目前为止,在每台设备上,相机预览视图都会按预期显示在顶部: 在此处输入图像描述

但在 iPhone 12 Pro 上,它的顶部有很大的差距: 在此处输入图像描述

如果我取消注释代码中的行,则图像现在以除 iPhone 12 Pro 以外的所有 iPhone 为中心。对于该设备,它居中加上原始顶部间隙,因此低于中心。

这是Apple方面的错误吗?

标签: iosswiftiphone

解决方案


推荐阅读