Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confused about orientation #242

Open
Vweston opened this issue Jan 20, 2021 · 4 comments
Open

Confused about orientation #242

Vweston opened this issue Jan 20, 2021 · 4 comments

Comments

@Vweston
Copy link

Vweston commented Jan 20, 2021

I’m confused. I created a new project. Added Swift package to project. Added a cameraView & label to storyboard. Build & run on device (iPad Pro 10.5” - iPadOS 14) in Portrait. Everything looks great. Camera view is correct. Rotate left & image is now displaying 90 degrees right. Rotate device back to portrait & camera image now incorrect there as well.

if I start out in landscape right. Then cameraView is rotated 90 degrees right, but is correct when back in portrait. I can only get it to correctly view in portrait mode no matter what settings I try. See images where the “This is a Label is always correctly displayed above cameraView.

here is my ViewController
//
// ViewController.swift
// BasicCameraManager
//
// Created by Vincent Weston on 1/20/21.
//

import UIKit
import CameraManager

class ViewController: UIViewController {

@IBOutlet weak var cameraView: UIView!

let cameraManager = CameraManager()

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
    //cameraManager.shouldKeepViewAtOrientationChanges = false
    //cameraManager.shouldRespondToOrientationChanges = false
    
    cameraManager.addPreviewLayerToView(self.cameraView)
}

}

Start in Portrait
IMG_5991

rotated
IMG_5992

Started in landscapeRight
IMG_5993

Rotated back to portrait
IMG_5994

any help would be really great.👍

@murraysagal
Copy link

@Vweston Same here. Did you ever find a solution for this?

@murraysagal
Copy link

I have the same issue. Here are the details:

  • I'm on Xcode 12.4 (12D4e), the latest as of today.
  • Create a new empty template app
  • by default in Deployment Info the iOS target is 14.4 and both iPhone and iPad are checked
  • pod init and then configure Podfile as per your instructions
  • pod install, when it's finished Podfile.lock says that 5.1.3 was installed.
  • Add the required privacy entry to info.plist
  • in ViewController add let cameraManager = CameraManager()
  • and in viewDidLoad() add let cameraManager = CameraManager()

I'm running on two devices. An iPhone X with 14.4.2 and an iPad Mini (5th generation) also on 14.4.2. I get the same results on either device.

  1. Start in Portrait. Everything is as expected.
  2. Rotate to landscape, either way. Two things happen. The view is rotated 90 deg off from what it should be. And the view is cropped towards the home button.
  3. Rotate back to portrait. The view remains cropped and is still 90 deg off.

I notice that the default value in the source for shouldKeepViewAtOrientationChanges is false. So I create a CameraManager subclass and override shouldKeepViewAtOrientationChanges so it returns true. In ViewController I change it to let cameraManager = MyCameraManager()

Then run:

  1. Start in Portrait. Everything is as expected.
  2. Rotate to landscape. Same result as before. The view crops and is off by 90 deg.
  3. Rotate back to portrait. This is correct now. Proper orientation and not cropped.

I haven't found a solution for the orientation issues but viewWillTransition() helped with the cropping.

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransition(to: size, with: coordinator)
    cameraManager.addPreviewLayerToView(view)
}

I don't know if that's the best solution for that.

Can you provide any help on the orientation issues?

@qhu91it
Copy link

qhu91it commented Jul 11, 2021

For my case, I setting like that

cameraManager.shouldKeepViewAtOrientationChanges = false
cameraManager.shouldRespondToOrientationChanges = true

And in where do the update UI when rotation change like viewWillTransition for example (me is updateUIView because I code SwiftUI), call resetOrientation function

DispatchQueue.main.async {
    self.cameraManager.resetOrientation()
}

@joopvanduin
Copy link

qhu91it Thank you that solved my problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants