Detecting iPad launch orientation - ipad

I'm developing an app that will feature a splash screen fading to the first app page. This splash screen is supposed to seamlessly flow from the Default-X.png image from the app launch. I've got this working great, except for one very special situation.
If the user taps the app icon, then IMMEDIATELY changes orientation, the automatic Default-X.png will come up from the original orientation (as expected), but my programmatically-defined intro image comes up in the new orientation. (I guess this is expected, too, now that I think about it.)
My question is, how can I get the actual launch orientation. NOT the orientation available when the app delegate starts, but the orientation of the device when the app icon is tapped, and therefor the orientation the OS uses to decide on the Default-X.png image.
Thanks.

I spent hours on this, then I found this and it saved me.
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
UIInterfaceOrientation orientation = [UIDevice currentDevice].orientation;

Related

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?

iphone keyboard is rotating into landscape while app setting is portrait only

My app’s device orientation is set to portrait, however when rotating the device into landscape mode, the app is keeping its portait mode but the keyboard is rotating into landscape mode...Something that is unexpected.
Why is that happening and how to prevent it?
Thanks
Jrejory
After not getting any answer and making more researches, I came across this Answer:
https://stackoverflow.com/a/6941930/4400274
Because I just needed the portrait orientation in my app the following worked for me :
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
I put that in my main Navigation Controller's viewDidLoad.
I know it's late. But maybe it will help someone else. I had the similar issue. My app should support portrait orientation for iPhone and all orientations for iPad. So, on the iPhone scene didn't rotate, but keyboard did. All my UI was made from code, I also init view controllers (including root) through code. But I didn't remove default Main.storyboard file. When I removed string in Target -> General -> Main Interface, it help me. It was not obvious.

Forcing Portrait Mode in a UIPageViewController on iPad

I have an iPad app which supports Portrait and Landscape in the entire app. This is an iOS 7 and iOS 8 version of an app.
The app is a UITableViewController with multiple segues to a different set of UIViewControllers. I have one option in the app to show the Tutorial again and I have created the images in a Portrait mode only orientation because it just wouldn't make too much sense (or look good in Landscape).
With this in mind, the tutorial is in the form of images loaded into a UIPageViewController. The images are loaded in the viewDidLoad and the buttons and layout work really well.
Issue
I want to restrict the UIPageViewController to be in a Portrait orientation only.
Currently, I have:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[[UIDevice currentDevice] setValue:
[NSNumber numberWithInteger: UIInterfaceOrientationPortrait]
forKey:#"orientation"];
}
That works to some extent. If the device is in Landscape mode and the tutorial is invoked, it rotates it to Portrait.
However, if the device is in Portrait and I rotate it to Landscape after invoking the Tutorial, the tutorial then rotates.
How exactly do I prevent this view from rotating in my custom UIPageViewController class, so that it never rotates to Landscape whether it's at the start, middle, or end of the tutorial.
Any guidance on this would really be appreciated.
Take a look at UIViewController docs for Orientation support, specifically shouldAutorotate: and supportedInterfaceOrientations- https://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIViewController_Class/index.html#//apple_ref/occ/instm/UIViewController/supportedInterfaceOrientations
My first guess would be you would want to set the value like you're doing now, and then override shouldAutorotate in your custom UIPageViewController subclass and return NO.
However, be aware you could get hit in the review process for HIG compliance, because your app claims to support all orientations, but parts of it don't. Obviously this is totally up to the reviewer and whether or not they catch it as plenty of other apps do this.

Why is the orientation wrong at app start?

I'm working on an iPhone app that supports both Portrait and Landscape orientations. When I start the app in Landscape mode and verify the orientation in the AppDelegate it returns Portrait orientation. After I rotate the device/simulator it returns the orientation correctly. It's an iOS 7 app. Anyone know how tot handle this? I need to know the orientation at startup for handling the UI.
UIViewController documentation says:
Note: At launch time, apps should always set up their interface in a portrait orientation. After the application:didFinishLaunchingWithOptions: method returns, the app uses the view controller rotation mechanism described above to rotate the views to the appropriate orientation prior to showing the window.
That's why it returns portrait mode first. More info in UIViewController documentation.

Get iPad Landscape Orientation in iOS5 at startup

I've got an iPad App with a TabBarController. Since iOS5 I'm note able anymore to get the correct orientation in the viedDidLoad or viewWillAppear when I start the app on the iPad in landscape. It always returns Portrait. When I ask for the orientation in viewDidAppear, everything is fine and correct. In iOS4 I was able to get the right orientation, but now I build for iOS5 ... not anymore.
Please. What can I do to get the right orientation on the iPad on startup?
This is how I get my orientation:
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
Thanks!
If you are loading any viewcontroller before loading RootViewContoller then Orientation of RootViewController needs to be set before adding it to window. you may find answer HERE

Resources