So I have an app that needs to not use autorotate. Instead of rotating the screen the buttons on the screen are just supposed to rotate.
I have the interface locked in landscape left. How do I detect what rotation the buttons should be?
I am using a custom opengl engine so I can set the rotation of objects.
You can get the device orientation from:
UIDevice.orientation
This is not the interface orientation, so you get two more possible values for face up and face down. Also the landscape left and right are swapped compared to UIInterfaceOrientation.
You can listen for changes in device orientation by subscribing to the UIDeviceOrientationDidChange notification from NSNotificationCenter. You may have to enable these notifications by calling UIDevice.beginGeneratingDeviceOrientationNotifications().
If the interface orientation is locked on the device, it is not listening to any delegate methods related to orientation changes.
Related
In Nativescript Angular, Is there anyway to detect orientation change and not allow content auto rotate but handling the content rotation manually? For example when rotating orientation from portrait to landscape, I want the content on the screen to stay still but i need to know that the screen is currently in landscape mode.
Im using nativescript-orientation plugin but this only allow me to disable the rotation. Once the rotation is disabled i could not detect the orientation change when the screen is landscape or portrait.
If you want to detect the orientation by yourself then you have to get the sensor data. I have never done this myself so I will just tell you where you can start. For IOS, you have get the sensor data from coremotion. You would require the data from the accelerometer and magnetometer sensors's data.
You can use the plugin nativescript-coremotion or You can directly access the IOS native methods yourself to do it.
My client asked me to rotate just labels and buttons when device is rotated. I turned auto-rotation off and made some affine transforms on the labels and buttons during the device rotation. But iOS thinks my app is in portrait orientation always, so the Notification Center can be dragged with finger from upper part of iPhone/iPad only and it is in portrait orientation always. Is there a way to change Notification Center orientation?
I can receive UIDeviceOrientationDidChangeNotification event, if auto-rotation is set.
But when screen auto rotation is disable, orientation notification doesn't work any more.
The effect I want to achieve is as iPhone Camera and Camera+: whatever the user lock or not lock the screen rotation, application can correspond to the rotation change immediately and correctly.
Does anyone has any idea why notification not sent when user lock the screen rotation?
How could I correspond to the device orientation change even if auto-rotation is disabled?
I also want to get the effect of the Camera app, where the app detects the orientation of the device even if the user has set Portrait Orientation Locked. UIDeviceOrientationDidChangeNotification is not posted when the user has portrait orientation locked. I believe the only way to determine the orientation of the device when the user has locked the orientation to portrait is to manually work out the orientation using UIAccelerometer.
The list of questions & answers below are all related to this issue. I found them when I was searching for an answer, and you might find them helpful too.
Related questions:
How to detect Camera Overlay view rotation
How to do Orientation Detection even the device has locked orientation
Detect iOS device orientation lock
Detect iPhone screen orientation
Callback method on auto rotation, iOS and iPad
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.
I am recreating the Camera app interface for my iPhone app. When it is rotated on its side, instead of rotating the entire UI, I only rotate the icons, just like the normal camera app does. This has worked just fine, but with iOS 5 the notification center orientation depends on the app's orientation. Since my app technically stays in portrait orientation, you can only access the notification center from the top of the screen, even when held sideways. The default camera app has somehow avoided this problem.
I figured the best way to do this is to silently update the UI to be in a different orientation, but from the user's perspective only the icons update. I've tried to achieve this by returning YES in shouldAutorotateToInterfaceOrientation:, and then setting the transform property to rotate the view in willAnimateRotationToInterfaceOrientation:duration:. This works, except it shows an animation where it moves the newly rotated view to its proper position. How can I achieve this without any visible animation?
The answer is actually very simple. All I had to do was change the statusBarOrientation property on [UIApplication sharedApplication] to whatever UIInterfaceOrientation I wanted.