imaginary-cloud / CameraManager

Simple Swift class to provide all the configurations you need to create custom camera view in your app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Auto lock & exposure not working

stowersjoshua opened this issue · comments

Adding focus and exposure locks appear to have no affect.
I'm using Swift 4.1 and deploying to an iPod Touch running iOS 11.2.1
Both features work as expected on the default camera app.

Variables

var cameraPreview = UIImageView()
var cameraManager = CameraManager()
var reticleView = UIImageView()

Loading the camera

Used every time the user needs to see the camera preview, and once just before taking a large set of photos automatically.

func pushCameraPreview() {
    self.view.addSubview(cameraPreview)
    cameraPreview.addSubview(reticleView)
    
    // Snap cameraPreview to center of screen
    cameraPreview.snp.makeConstraints { (make) -> Void in
        make.edges.equalTo(view).inset(UIEdgeInsetsMake(200, 20, 90, 20))
    }
    
    // cameraManager settings
    cameraManager.shouldEnablePinchToZoom = false
    cameraManager.shouldEnableTapToFocus = false
    cameraManager.addPreviewLayerToView(cameraPreview)
    cameraManager.shouldRespondToOrientationChanges = false // true
    cameraManager.shouldUseLocationServices = true
    cameraManager.flashMode = .off
    cameraManager.cameraOutputQuality = .high
    cameraManager.cameraOutputMode = .stillImage
    cameraManager.animateShutter = true
    cameraManager.writeFilesToPhoneLibrary = false
    cameraManager.focusMode = .locked
    cameraManager.exposureMode = .locked

    reticleView.image = UIImage(named: "crosshairs.png")
    reticleView.layer.masksToBounds = true
    reticleView.frame.size = cameraPreview.frame.size
    
    reticleView.snp.makeConstraints { (make) -> Void in
        make.edges.equalTo(view).inset(UIEdgeInsetsMake(210, 30, 100, 30))
    }
    
    self.view.layer.insertSublayer(reticleView.layer, above: cameraPreview.layer)
}

Hiding the camera preview

func popCameraPreview() {
    cameraPreview.removeFromSuperview()
    reticleView.removeFromSuperview()
}

Taking a photo

self.cameraManager.capturePictureDataWithCompletion { data, error in
    if let error = error {
        print("Camera error: \(error)")
        return
    }

    let imageName = message
    guard self.saveImage(withData: data!, imageName: imageName) else { return }
}

I'm pretty new to Swift. Let me know what other information might be helpful.

@stowersjoshua

sorry for the late response.

Have you tried to:

cameraManager.shouldEnableExposure = true ?