Confused about orientation
Vweston opened this issue · 4 comments
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)
}
}
any help would be really great.👍
@Vweston Same here. Did you ever find a solution for this?
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 configurePodfile
as per your instructionspod install
, when it's finishedPodfile.lock
says that 5.1.3 was installed.- Add the required privacy entry to
info.plist
- in
ViewController
addlet cameraManager = CameraManager()
- and in
viewDidLoad()
addlet 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.
- Start in Portrait. Everything is as expected.
- 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.
- 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:
- Start in Portrait. Everything is as expected.
- Rotate to landscape. Same result as before. The view crops and is off by 90 deg.
- 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?
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()
}
qhu91it Thank you that solved my problem