0

I have an application which has a Tab Bar Controller with two items in it. Each item has its own Navigation Controller. Each part of the application has different behaviors. So I am not able to control the device orientation app-wide. However, in the second part of the app, I mean in the second navigation controller, the behavior should be slightly different.

I have a parent view controller in the second navigation controller. It should be always portrait. So I have made it using a lock method from the answer: https://stackoverflow.com/a/41811798/2152616

Basically, I call lock methods and it works fine. It also pushes to another view controller on some user action. The second view controller does not need to support landscape. So I am able to use the same technique to lock the orientation to portrait. However, when user rotate the device to landscape the I should present another view controller. In the case I lock the orientation, I'm not able to detect the orientation change.

How can I detect the orientation while the view controller supports only portrait mode?

Onur Tuna
  • 1,030
  • 1
  • 10
  • 28
  • You can use "NotificationCenter.default.addObserver" method under the "didFinishLaunch" app delegate method, And pass the orientation check function under the selector of the same observer. It fires a notification when the device orientation changed. You can use that notification on the desired view controller and perform your task. – Ashutosh Mishra Jul 17 '20 at 16:57
  • That's worth trying. I'll try it and give a feedback. – Onur Tuna Jul 18 '20 at 12:29

0 Answers0