4

I'm trying to make an iOS app featuring some AR experience using ARKit. The app now has a start-up view with a "start" button (which shows first after the app is just launched) and a AR View (which shows after I tap the "start" button in the start-up view), and I also have viewcontrollers for each one. The AR view is essentially a full-screen ARSCNView which shows the real-time image from the camera, plus some UIButtons.

All the things seem to work well until I want to specify the orientation in each stage. It's required to make the start-up view portrait and the AR view landscape-right. In order to change the orientation of the screen automatically, I tried to add the following code into viewDidLoad() for the AR ViewController :

let value = UIInterfaceOrientation.landscapeRight.rawValue
UIDevice.current.setValue(value, forKey: "orientation")

and set

override var shouldAutorotate: Bool {
    return false
}

However, it didn't work well --- Although the orientation of the UI was changed correctly, the camera preview was also "rotated" by 90 degrees (so all images you would see from the app will be rotated by 90 degrees):

image1 (The device is now physically portrait, the camera view is somehow vertical)

image2 (The device is now physically landscape-right, but the camera view is still vertical)

I also tried another method:

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask.landscapeRight
}

But it ended up the same way.

I want it to be like below, the UI is fixed in landscape-right but the camera is always in the normal orientation (gravity-down):

image3 (This is captured with autorotate allowed, but I want it to rotate automatically on switching to this view!)

Any help or hint would be much appreciated!

Axel Guilmin
  • 10,343
  • 7
  • 49
  • 59
Lemon
  • 41
  • 2
  • I'm having the same issue. did you ever figure it out? It seems that this person had the same issue but solved it on his own: https://stackoverflow.com/questions/45125709/setting-arkit-orientation-via-swift – somosomo Mar 20 '19 at 19:17

0 Answers0