Get "locked orientation", also known as "view orientation" - ios

I have locked the orientation via XCode to be either landscape-left and landscape-right, but using UIDevice.current.orientation is giving the orientation as if it was not locked. Like when I am physically (in real life) in portrait, but my view is locked in landscape-left, I want to still get landscape-left, is this possible?
I can of course get the non-specific orientation by testing if width > height. But i needed the specific orientation of either landscape-left or -right.

Instead of asking the device for its orientation, ask the app for its orientation, by asking for UIApplication.shared.statusBarOrientation.

Related

How do I programmatically control device orientation's effects?

Scenario: I set the default device orientation to portrait. However, there are some Views that I want to allow for landscape mode.
Most of my views don't need to be in landscape. But there are some with orientation detection that allows a full-size linear graph to be displayed in landscape mode.
I want my application to behave as a Portrait-Centric for most of the time.
Question: How do I freeze the Portrait when I need to, but allow for Landscape when the situation warrants it?
You can manually allow, and most importantly in your case, disallow device orientation through UIInterfaceOrientation. Full description was already answered here: https://stackoverflow.com/a/40859280/13296047

Ask permission to unlock screen orientation in Swift

I'm working on a photo capturing application.
My app only supports portrait mode and I have to rotate landscape images to rotate them for the portrait mode. For example I want to rotate the photo 90 degrees right if it was captured in landscapeRight.
But if user device is in "Lock screen orientation" mode, I can't get the correct device orientation value with UIDevice.current.orientation if user is trying to take a landscape positioned photo. It always returns "portrait" value of course due to the "lock screen oritentation".
I want to ask permission to user for unlocking screen orientation with like "This application wants to unlock your screen orientation" message. Is it possible to add my info.plist to add a permission request for unlocking screen orientation? And if yes, which permission do I have to add in my info.plist?
Thanks in advance.
I concur you can't change the orientation properties. All those properties (in your project page) do is to enable state variables and notifications from which you can animate the orientation of your UI. So perhaps a hacky solution would be to look at using gyroscope APIs, and to make a small algorithm based on that to detect device rotation. It would essentially come down to building logic similar to a Leveling App. https://developer.apple.com/documentation/coremotion/cmmotionmanager

App Orientation in iOS9 Split View

I'm looking at how my app will run in Split View on an iPad Pro.
I use constraints for layout, but sometimes I want to know the window orientation in order to tweak the layout by modifying a couple of constraints.
Things are easy to handle if the user rotates the device (I handle the call of viewWillTransitionToSize), but the app has to know its initial orientation.
Until now, I have been using the status bar orientation to determine the device orientation:
UIInterfaceOrientation o = [[UIApplication sharedApplication] statusBarOrientation];
But this doesn't seem to work properly in Split screen mode on the iPad Pro simulator. The problem is that the device is in landscape mode, and the statusbarOrientation call says the app is in landscape mode. But my app is using half the screen, so it needs to do layout as if it's in portrait mode.
If I check the bounds size of myViewController.view, this seems to give the right answer, even if the device has not been rotated. In the bad old days I seem to remember that we couldn't rely on this unless the device had been rotated at least once.
So what's the right way to determine the orientation of my App window in iOS9?

shouldAutorotateToInterfaceOrientation gets called but app interface does not reorients (only the status bar reorients)

I am trying to build an app that only works for landscape device orientations on iOS devices. That means my shouldAutorotateToInterfaceOrientation returns true for only landscape device orientations. However at some points of time, I need to switch to portrait device orientation for which I use setStatusBarOrientation API.
After holding the device in any landscape orientation and setting the interface orientation to default/upside down by using setStausBarOrientation API, and just tilting the device slightly in the held orientation orientation only, the status bar rotates but the interface does not rotates. shouldAutorotateToInterfaceOrientation does get called and returns true but still interface does not reorient. Also, problem gets solved if I rotate the device in opposite orientation. I am not sure what I am doing wrong.
Apple have accepted this as a bug in their SDK and they might fix the issue in the next release.

Starting iPad app in current landscape orientation

My ipad app only runs in landscape orientation. But when I test on an actual device (not the simulator) it always seem to start in one particular landscape orientation, then turn 180 degrees to match the current physical landscape orientation. So, it seems to start in LandscapeLeft(I think) then rotate 180 if I have it in LandscapeRight. There's nothing in Info.plist to set the initial orientation.
Can anyone suggest a way to detect current orientation before view loads and set it to correct landscape view before showing?
Thanks
Fitto
There is the UIInterfaceOrientation~iPad key which sets the initial interface orientation on startup.
There is also the UISupportedInterfaceOrientations key which informs the app which orientations are supported.
There is no way, however, to make the app start in the current orientation of the iPad.
Have you looked into these questions?
Get current orientation of iPad?
iPad launch orientation
Also, technically, the iPad should just do it. Make sure you have supported orientations set properly, as I'm sure it checks those to see where it should start.

Resources