0

我遇到的主要问题是我的相机。主要问题是相机在 iPhone X、Xs、Xs Max 和 XR 型号上放大得太远。

我的相机是全屏相机,在较小的 iPhone 上还可以,但是一旦我使用上面提到的型号,相机似乎就卡在了最大缩放级别。我真正想要完成的是类似于 Instagram 相机工作原理的性质。在 iPhone X 系列之前的所有型号上它都是全屏的,然后似乎尊重边缘插图,或者如果它将是全屏,我希望它不会像现在这样放大。

我的思考过程是使用这样的东西。

  1. 确定设备。我想我可以使用 Device Guru 之类的东西来确定设备的类型。

GitHub repo 可以在这里找到 --> https://github.com/InderKumarRathore/DeviceGuru

使用此工具或类似工具,我应该能够获得设备的屏幕尺寸。然后我可以做一些数学运算来确定相机视图的正确屏幕尺寸。

假设 DeviceGuru 不起作用,我只会使用这样的东西来获取屏幕的宽度和高度。


// Screen width.
public var screenWidth: CGFloat {
    return UIScreen.main.bounds.width
}

// Screen height.
public var screenHeight: CGFloat {
    return UIScreen.main.bounds.height
}

这是我用来填充相机的代码块。但是,我想变成基于设备大小的东西,而不是尽管有电话但只是填充它


import Foundation
import UIKit
import AVFoundation

class PreviewView: UIView {
    var videoPreviewLayer: AVCaptureVideoPreviewLayer {
        guard let layer = layer as? AVCaptureVideoPreviewLayer else {
            fatalError("Expected `AVCaptureVideoPreviewLayer` type for layer. Check PreviewView.layerClass implementation.")
        }
        layer.videoGravity = AVLayerVideoGravity.resizeAspectFill
        layer.connection?.videoOrientation = .portrait


        return layer
    }

    var session: AVCaptureSession? {
        get {
            return videoPreviewLayer.session
        }
        set {
            videoPreviewLayer.session = newValue
        }
    }

    // MARK: UIView

    override class var layerClass: AnyClass {
        return AVCaptureVideoPreviewLayer.self
    }
}

我希望我的相机看起来像这样

Instagram

或这个

SnapChat

不是这个(我现在的相机是什么样的)

My Camera

I have looked at many questions and nobody has a concrete solution so please don't mark it as a duplicate and please don't say it's just an issue with the iPhone X series.

4

1 回答 1

1

Firstly, you need to update your code with the apt information, since this will give a vague idea to a anyone else with less experience.

Looking at the Images it is clear that the type of camera you are trying to access is quite different than the one you have. With introduction of iPhone 7+ and iPhone X, apple has introduced many different camera devices to the users. All these are accesible through AVCaptureDevice.DeviceType.

So by looking at what you want to achieve, it is clear that you want more field of view within the screen. This is accessible by .builtInWideAngleCamera property of the above given capture device. Changing it to this will solve your problem.

Cheers

于 2019-01-26T17:00:12.520 回答