How do I programmatically control device orientation's effects? - ios

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

Related

Ios: how to avoid video orientation change during capture?

I have an iOS app that only supports portrait. When rotating the device the video captured by the RTCCameraVideoCapturer (WebRTC) rotates to landscape orientation, even when the rest of the UI stays in portrait. How to avoid this?
Do you have access to RTCCameraVideoCapturer codebases ? Also, I am not sure which version of the WebRTC codebases you are working with. And, in your application ; is landscape mode is the only mode that you are intending to support ?
There should be rotation calculation method that listen to rotation changes. You can just disabled it, or can use your preferred fixed set of rotation in spite of default.
For example, taking from this sample codebase ; you can just only use RTCVideoRotation_90 to have landscape orientation only.

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?

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.

iPad orienatation need :application rejected

I want to know that does apple approves application having any two of the orientation?
Like Landscape Left and Landscape right ,
Or Portrait mode and Portrait mode Upside down,
My application is having functionality of Drawing and to shows number of images .
Is it only required or I need to use all orientation for the application.
I had put only one orientation and application was rejected but I came to know from some sources that apple allows any two of the orientation , Is it true?
Thanks in advance.
Judging from the thread in the comments below I think you need to support at least 2 rotations. So Both portraits or both landscape or all 4 rotations.
(in my opinion, if your app is landscape you must support both rotations, if it's portrait Apple may be more accepting if you don't support portrait upside down)
Apple require that for iPad you must support all orientations. That's just fact, and there is no possibility to do anything with that.

Resources