I have developed an iOS App and tested it on iOS6 device. While testing, I realized that my App is not responding to Orientation changes as expected.
Here is my Code:
// Autorotation (iOS >= 6.0)
- (BOOL) shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationMaskPortrait;
}
Precisely, I want to know that what Methods are called on Orientation Changes in iOS.
The accepted answer reads the orientation of the device as above, which can be reported differently than the orientation of your view controller(s), particularly if your device is held in an almost horizontal position.
To get the orientation of your view controller specifically, you can use its
interfaceOrientation
property, which is deprecated since iOS 8.0 but still reports correctly.In your ViewController, you can use
didRotateFromInterfaceOrientation:
method to detect when the device has been rotated and then do whatever you need in every orientation.Example:
You can try this, may help you out:
How to change the device orientation programmatically in iOS 6
Objective-c:
Swift:
/* You need to declare these code in your ViewDidload or ViewWillAppear */
/* Now Our Device will give a notification whenever we change the orientation of our device,So you can control your code or program using the current orientation */
You can try this, which solves your problem.
Refer below link for
App extension
Get device current orientation (App Extension)Follow the documentation on UIDevice.
You need to call
Then every time the orientation is changed you will receive a UIDeviceOrientationDidChangeNotification.