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);
}
Related
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.
My fellow students and me coded a objective-c program for iPhone.
But we have a big problem:
Our App is coded in Portrait-mode, but 2 or 3 Views should be displayed in Landscape-mode (directly).
We activated Landscape autorotation in these views, but, if we open one of these views now, we get Portrait again and it only turns into Landscape, when we turn the device.
(Already on our test-device, no problem of the IOS-simulator!)
Can anybody help us please?
The only thing that worked for me was using
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
in my ViewController and presenting it with presentModalViewController.
This forces the View to stay in landscape.
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.
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,
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...)