iphone xcode Landscape mode by default - iphone

how can I set an iphone app to start in Landscape mode? and stays that way

Set the "Initial interface orientation" app.plist entry to "Landscape" (left or right home button) and add (or more likely, uncomment and edit) the following view controller method:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

Marcelo's answer is not correct, because UIInterfaceOrientationLandscape is not a valid identifier and thus brings up a build fail.
progrmr's answer is correct:
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;
(Apologies for not commenting on the first answer, but I didn't have enough reputation points when I wrote this...)

Related

App Rotating Even Though I Told it Not To

Wrote an app with Xcode. Clicked the buttons that restrict orientations to be the two portrait options. Changed the plist file to only allow the two portrait orientations. Put the restriction in programatically.
When I build the app to my phone, it rotates into both landscapes and the upright portrait orientation. What the heck?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return ((interfaceOrientation == UIInterfaceOrientationPortrait) ||
(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
}
The method you're using is part of the controller class, but that method may never get called if the controller class is either not active or not in control of the view on the screen. So your app might be auto rotating because this message is in fact never actually getting called. The solution is to check the connections or initializations of your view controller class to make sure that they are running as you expect.

Locking the orientation in an iPad app (plist or UIViewController?)

I'd like the app to work like it would be as if I locked the orientation manually. I'm trying to find how I can lock the orientation for an app. In the info.plist, I have this setting:
Supported interface orientations (iPad)
Item 0 Landscape (right home button)
Item 1 Landscape (left home button)
I thought that would be enough to keep my viewControllers from staying in landscape mode and not portrait. But it does not. Do I need to do
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
in ALL my viewControllers? Thanks!
All though implementing shouldAutorotateToInterfaceOrientation in all your view controllers will work, it is probably not the fastest or most practical way of doing what you are trying to accomplish.
If any of your view controllers in your hierarchy do not conform to the orientation change, then iOS will stop trying to rotate them. What this means is that only your root view controller needs to have implemented shouldAutorotateToInterfaceOrientation with only landscape orientations. Each view controller pushed or added will conform to that function.
I have had to do this in several of my apps and it was required for several reasons.
In the end and after a lot of testing, we determined that the condition has to be set on the info.plist AND on every viewController.
So make sure it is set on the plist and that every shouldAutorotateToInterfaceOrientationonly returns yes for the allowed orientation.
This is because the plist will help you with allowed LAUNCH orientations, but your app could still rotate afterwards, specially when using modal views.
You can download one of my free apps that does thins on iPad: http://itunes.apple.com/mx/app/hoteles-city/id471505865?mt=8
Yes you do.
I have a different solution however. In every UIViewController, I use:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
} else {
return NO;
}
}

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.

Enable iPhone Interface Orientation

I'm trying to get my application to rotate the interface when the device itself is rotated, but I can't get it right.
I have added the supported interfaces in the plist info file and returned yes for the shouldRotateToInterfaceOrientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
return YES;
} else {
return NO;
}
}
Is this how rotation is implemented?
Please help!
Maybe try editing the info.plist and also add your supported orientations there?
Select your project --> Select your target --> Info --> Supported interface orientations and click on the plus sign 4 times to support these orientations:
Item 0 Landscape (left home button)
Item 1 Landscape (right home button)
Item 2 Portrait (top home button)
Item 3 Portrait (bottom home button)
Hope it helps!
Make sure you've added shouldRotateToInterfaceOrientation to the view controllers that you want to support different orientations. It doesn't go in the app delegate.
Supporting orientation is straight-forward if you're using standard UI elements so, assuming that's the case, you're on the right track.
If you're using a UITabController, all the views must support the same orientations, otherwise it defaults to the minimum (e.g. Portrait), I believe.
Also, if you're using NIBs for your views, make sure you have 'Autoresize subviews' checked when configuring the view in Interface Builder.
if you are using UITabBarController, then you'll need to call it's subviews' shouldAutoratateToInterfaceOrientation.
suppose you have two tabs, please try to add the following two lines to method shouldAutorotateToInterfaceOrientation in the class that uses the UITabViewController.
[[tabBarController.viewControllers objectAtIndex:0] shouldAutorotateToInterfaceOrientation:interfaceOrientation];
[[tabBarController.viewControllers objectAtIndex:1] shouldAutorotateToInterfaceOrientation:interfaceOrientation];
of course the "tabBarController" must be linked to the UITabBarController in your XIB file via IB.
Thanks,

iPhone - Landscape Only App

I am trying to make an app that will only be viewed in Landscape. I have looked up some tutorials (albeit older ones) and have done the following:
-set up the info.plist to include a key for uiinterfaceorientation
-in the main view controller I have set the frame to be 480 x 320
Now, the first screen loads up ok. Everything is where it should be and whatnot. However, if I click a button that is set to present a modal view controller nothing happens. Everything is linked and coded correctly but nothing happens when I press the button. Am I doing something wrong with trying to force landscape?
At it's basic, this question is a how do you effectively make an app that will only be in landscape mode? Thanks for any help.
You should only uncomment this method I show you below:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}