iPad launch orientation not detected - iphone

I have an iPad app that works correctly except for an odd issue during launch. I've read several questions & answers regarding orientation, but this still has me stumped.
The root view controller is a UITabBarController with 3 tabs. Two of the tabs are have custom view controllers (one based off of UIViewController, the other off of UITableViewController) and both suffer from this launch orientation problem. The third tab is a custom UITableViewController that's embedded in a UINavigationController.
OK, here's the problem. If I start the app in Portrait orientation, everything works great. If I start it in Landscape orientation, the 3rd tab works perfectly. However, the first 2 tabs come up in Portrait orientation, even though:
The status bar orientation correctly shows as landscape (spread across the screen).
The Tab Bar view correctly shows as landscape with the tabs centered.
All views return YES for shouldAutorotateToInterfaceOrientation for all orientations.
If I call [self interfaceOrientation] or [[UIApplication sharedApplication] statusBarOrientation] in the view controller's viewWillAppear, then the 3rd tab's view controller reports 3 (landscape) but the first two view controllers report 1 (portrait) even though the status bar is clearly landscape!
If I rotate the iPad to portrait and back to landscape, then all 3 tabs' views rotate correctly (and the methods above return 3, as expected).
Also, if I tap on any other tab and then back on tab #1 or #2, then they will now rotate correctly, even without rotating the iPad itself!
What am I missing?

You have to add the supportedDeviceOrientations to your "myApp.plist" .
Click on this list, add the key "Supported interface orientations" and add the supported interface orientations. This solved the problem for me.
For further informationen follow this link and go to the section "The Application Bundle": http://developer.apple.com/iphone/library/documentation/General/Conceptual/iPadProgrammingGuide/CoreApplication/CoreApplication.html

I finally found my answer: I just forgot this in my LoadingController.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}

I have found that the device orientation starts out with nothing. And should return YES for Unknown. This will allow it to orient the device with the correct launch orientation.
Here is the code I used to propigate this message up to the legacy messages.
- (BOOL)shouldAutorotate{
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
if (orientation == UIDeviceOrientationUnknown) return YES;
BOOL result = [self shouldAutorotateToInterfaceOrientation:orientation];
return result;
}
notice I return YES if orientation == UIDeviceOrientationUnknown. This corrected my loading problem.

The solution is to add a key
UISupportedInterfaceOrientation
to you Info.plist with an array of strings specifying the suppored interface orientations at launch time, these are
UIInterfaceOrientationPortrait
UIInterfaceOrientationPortraitUpsideDown
UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight
However, there is the follwing issue which may lead to confusion: At least with SDK 3.2 and iPad Simulator from XCode 3.2.4 I found that (at least some) Info.plist settings appeared to be cached and/or are not updated when installing the app. That is, adding the key above and installing and launching the app in the simulator had no effect. However, deleting the app from the simulator fixed the problem an the newly installed app behaved as specified.

In your app delegate's applicationDidFinishLaunchingWithOptions: method, after you add your view controller's view to the window, add the following:
[myViewController viewDidLoad];
If necessary, this will trigger a call to the shouldAutorotateToInterfaceOrientation: method.

just try this
- (BOOL)shouldAutorotateToInterfaceOrientation: UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown);<br>
}

Related

IOS 6 Storyboard rotation doesn't work as expected

I'm developing an iOS6 App with storyboards and i'm encountering an unexpected beahviour.
My app is almost in portrait mode , and i would keep this orientation in all the views except two.For this reason the project supports both landscape and portrait mode, i've subclassed navigation controller with a category (as explained almost everywhere :-)in Appdelegate.m and every view controller implements
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait; (landscape where needed)
}
and
-(BOOL)shouldAutorotate{
return YES;
}
Everything seems to work well except the fact that in the transition between a landscape view to a portrait one (not vice versa ?) , all the elements of the ui are displayed in landscape(imagine that you're keeping the phone horizontal), if you turn the phone , the rotation event is fired, the ui turns back in portrait and only now is locked to this orientation.Is there a way to fire the rotation BEFORE the view is presented?
Why the shouldAutorotate is not called at the ViewWillAppear stage?
Thank you!
Remove both the above function and try this it should work
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
Return YES for supported orientations
}
if still it's not working then try this change the appDelegate
[window addSubview:nav.view];
to this code
window.rootViewController=nav;
I found this online chapter very good for explaining UIViewControllers and rotation.
http://www.apeth.com/iOSBook/ch19.html#Rotation
It s a big page, scroll down to Rotation.

UIView always loads in portrait mode

This one has me ripping my hair out. My iPad application is setup as follows:
In my app delegate I have this:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
in my info.plist I have:
Initial Interface Orientation = UIInterfaceOrientationLandscapeLeft
In my first view controller that is loaded from the app delegate I have:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations.
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
In my second view controller I have:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations.
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
Finally the views in both nibs are set to landscape in Interface Builder. The application starts in landscape mode and there is a button that when pressed assigns the second view to the first view:
self.view = secondView.view;
the problem is that even though everything is in landscape the new view is always loaded in portrait mode? Please any help on this would be very very appreciated!
This is the bit you want to change. This is what sets the allowed initial orientations. Change it to suit your needs.
It's in the summary tab of the Target's settings.
Or. if you aren't using Xcode 4 yet - you can set the orientations in the Info.plist:
And so you can see all the keys:

Xcode 4 component orientation problem

I'm using xCode 4 for my project which should work both on iPad and iPhone. So, i have created Universal windows based application. I want my application starts into landscape mode so i added following:
in method:
shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
I set interfaceOrientation == UIInterfaceOrientationLandscapeRight
and added the key into application.plist:
Initial Interface Orientation and set it on Landscape (right home button).
Now, the application did start in landscape mode, however, every component in it (button, label) remains rotated 90 degrees (counterclockwise).
When i load xib, Window orientation is set into Portrait and dropdown is disabled.
anybody has idea what i'm doing wrong?
shouldAutorotateToInterfaceOrientation isn't asking you to set the variable (and will have no way of reading the result even if you do), it's a query as to whether the nominated orientation is acceptable. So you want:
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationLandscapeRight) return YES;
return NO;
}
/* or: return interfaceOrientation == UIInterfaceOrientationLandscapeRight; */
The XIB is a separate issue; neither Interface Builder nor its replacement parts in Xcode 4 can see what you're doing in your code, so they shouldn't just decline to let you design in landscape mode. However, it's the view that is linked to the view member of the relevant UIViewController that you want to set the orientation on, not the window.

iOS how to stop view rotate

I want my iPad app to stop rotation as you rotate the iPad. I want to stop rotate every view.
Any ideas help?
if you want stop rotation for whole app then simply in app info.plist file changed Supported interface orientations ,Initial interface orientation property to portrait or landscape depends on you
In iOS6 shouldAutorotateToInterfaceOrientation has be deprecated. Override both supportedInterfaceOrientations and preferredInterfaceOrientationForPresentation instead.
Please see
Just check the auto-resizing property of your view controller.
(Fixed syntax error)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationPortrait)
return YES;
return NO;
}
In My Project's info.plist I have deleted some key on the iPad Supported interface orientations like the following image (I have only given support for the portrait orientation)
The main idea of global controllable rotation lock is to write UIViewController category containing lock mechanism for every view controller.
You simply need to modify supportedInterfaceOrientations method globally
- (NSUInteger)supportedInterfaceOrientations
{
return __orientation;
}
Here __orientation is the static variable which can be set via category method.
The full realization of the category is presented here
Please update your projectname.plist like this. Supported interface orientations have only one object "Portrait (bottom home button)"
I strongly advise against stop rotation on iPad because supporting rotation is a must on the iPad. This is because the iPad does not have a normal way in which it will be held unlike the iPhone, which is normally held in portrait view (AKA Vertical). So you have to leave the choice to the user to eventually lock the orientation
The HIG do not actually state this as a requirement, but as a recommendation but there are many app that was rejected by this issue.
By the way if you want to this for a limit number of view controller you should implement:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if(interfaceOrientation == UIInterfaceOrientationPortrait){
return YES;
}
}

Launching application in landscape orientation for IPad

Facing one issue with launching application in landscape orientation for IPad.
I have developed IPhone application which later I ported to IPad.
I have made setting regarding orientation in info.plist
[ UISupportedInterfaceOrientations~ipad ] to support all orientation UIInterfaceOrientationPortrait , UIInterfaceOrientationPortraitUpsideDown , UIInterfaceOrientationLandscapeLeft , UIInterfaceOrientationLandscapeRight.
but when I start IPad application in the landscape mode, it always start in the potrait mode.
Along this
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{ return YES; }
help me, if I am missing something with this..
Thanks,
Sagar
here's something I also discovered: setting the initial interface orientation in your info.plist is being ignored if you have Supported interface orientations set up with another orientation in the first slot! Put your initial orientation there as well - and the simulator will launch correctly, as will the app. this drove me nuts for a long time!
Put UISupportedInterfaceOrientations into your -Info.plist, with a setting for each orientation you support. This is used to see which orientation the app can start in. From there onwards it will ask your view controllers.
Sagar - I had the same issue but was able to resolve it.
Like yours, my app started as an iPhone app which I "upgraded" to a Universal app using the XCode wizard. I noticed that when running on the actual iPad, starting in landscape, the app would start in Portrait, then maybe rotate to Landscape. On the simulator, starting in landscape, the app would start in Landscape, then the simulator would rotate to Portrait.
On the iPad, my app is a split-view app with TabBarControllers on left and right. Each tab is a view controller that returns YES to shouldAutoRotateToInterfaceOrientation.
I noticed that a brand-new wizard-generated, simple-case with a splitviewcontroller, Universal app didn't have this problem.
The difference I found between my app and the simple-case was that I wasn't adding my splitview-controller's view to the app window in applicationDidFinishLaunchingWithOptions. Instead I was showing a "loading" view at this stage, then later when an initialization thread completed I'd add my splitviewcontroller's view (and hide the "loading" view).
When I added my splitviewcontroller's view to the app window during the call to applicationDidFinishLaunchingWithOptions everything started working fine.
There must be some magic that happens on return from applicationDidFinishLaunchingWithOptions???
Is your app similar to mine in that it isn't adding the main view controller's view to the window during applicationDidFinishLaunchingWithOptions?
As pointed out in a number of posts, you must set up the info.plist with both the supported and the initial interface orientations. However, the bigger issue is when does the initial orientation become effective? The answer is NOT when your view controller receives the "viewDidLoad" message. I found that on the iPad-1, running iOS 5.0, the requested initial orientation becomes effective only after several "shouldAutorotateToInterfaceOrientation"
messages are received.(This message passes the UIInterfaceOrientation parameter to the receiver.) Furthermore, even if the orientation says it is in Landscape mode, it may not be! The only way I found to be sure that the view is in Landscape mode is to test that the view height is less than the view width.
The strategy that worked for me was to lay out the subViews I wanted when the "viewDidLoad" message was received but to delay actually adding those subViews to the view until the controller received a valid "shouldAutorotate.." message with the orientation set to Landscape mode. The code looks something like:
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
// N.B. Even when the interface orientation indicates landscape mode
// this may not really be true. So we insure this is so by testing
// that the height of the view is less than the width
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
CGRect viewBounds = [[self view] bounds];
if ( viewBounds.size.height < viewBounds.size.width )
[self addMySubViews];
return YES;
}
else
return NO;
}
Apple has just released iOS 5.1, so this behavior may have changed. But I expect the code that is here should still work.