I have just completed building a universal app which rotates perfectly on my iPhone, but on the iPad it just stands still.
Similar to this question, but that does not solve my issue.
The supported interface orientations are all set to allow rotation and I have even set this in my app delegate:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
Still the iPhone rotates fine, but the iPad won't move from portrait.
What could cause this, or rather how can I fix it?
[UPDATE]
The switch on the side is not on lock.
The orientations in the PList are set correctly.
The Project settings (where you select it via buttons) are set correctly.
#adam-s was right, except with Xcode 7.x there is no button below the "devices" selector.
With Xcode 7, you need to change "Universal" to "iPad" whereby the orientation selectors change to reflect iPad-only settings. Then you can change the selector back to "Universal".
Confusing!
Don't forget to change the rotation settings for the target for both iPhone and iPad - note that there's an iPad button to the right of the iPhone one (which some people, such as myself, might miss at first glance):
I fixed this by adding this piece of code to every ViewController of mine:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
It seems like this question's answer was correct after all. I just thought it wasn't since I checked through all the ViewControllers and found nothing restricting it from turning.
Related
I'm new to IOS development, and I'm trying to write an app for deployment on an ipad. Partly to keep things simple, layout-wise, and because I believe that my users will only use the app in landscape mode, I wish to only allow landscape views, and completely disable portrait views.
I've found a good deal of advice looking around the internet for an answer. Unfortunately, none of it has worked for me. The best answer I've found was to simply to go the target in xcode, and under "deployment info" -> Device Orientation, simply uncheck "Portrait" and "Upside Down". This should, theoretically, solve my issue, but unfortunately, it does not. The view rotates just as normal to portrait mode.
Going to the info tab and setting the Initial Interface Orientation to Landscape (Left) does make the app at least start in Landscape mode, but it does not restrict it only to that mode.
Even adding
- (BOOL)shouldAutorotate {
return NO;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
into my main view doesn't seem to help anything. So I'm somewhat stumped. There must be some setting or something somewhere which is still allowing portrait views. What might this problem be?
If you look at your AppName-Info.plist file, there should be a key titled 'Supported interface orientations'.
You should remove any of the Portrait values in that dictionary and make sure you only have the Landscape values included!
Edit:
In the question-asker's case, their issue involved a piece of code in the AppDelegate that changed the app's supported orientations.
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
/* They had the following:
* return UIInterfaceOrientationMaskAll;
* Which allowed the orientation to rotate to portrait
*/
// This fixed their issue:
return UIInterfaceOrientationMaskLandscape;
}
Hope this helps!
You can do this in General tab in your project
I have an app supports both orientation portrait and landscape. But in a viewcontroller I JUST want it present in LANDSCAPE mode. I try overriding some methods for changing orientation such as
- (BOOL)shouldAutorotate {
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return (UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight);
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
return YES;
}
return NO;
}
But none of them are called in iOS 9. Therefore, this viewcontroller present both portrait and landscape. On contrary, it works perfectly in iOS 8.
So annoying, is there anyway to force just a viewcontroller presented in landscape mode in iOS 9
UPDATE:
As Ronak Chaniyara's answer, I solved my problem, just one controller is in landscape mode.
Now I face another problem. If I want to force one controller just in portrait mode, I implement these methods in the controller but it's still rotated if I rotate screen.
Is the solution still work with portrait mode, or I have to find another approach to force a controller just in portrait mode
I think issue will be you have defined the allowed orientations in info.plist which apparently overrides anything you do anywhere else throughout the project.
To correct the issue I removed the entries from info.plist and defined them in the project settings. Now everything works as expected.
Hope this helps.
Look at your info.plist file. Here you have a key named "Supported Interface Orientation" with a group for the iPhone version and another for the iPad.
Here you can delete the value "Portrait (bottom home button)", and replace it by "Landscape (left home button)" or "Landscape (right home button)".
I hope it helped!
In this way, you can do:
Go to target setting
Go to development info
Change device orientation to landscape and uncheck all other option.
Hope this help you
My app was originally created for iPad, in Landscape orientation. Now I've to make it compatible with iPhone.
Converting Storyboard from iPhone to iPad
I followed this thread to copy my storyboard and define it for iPhone. In the project settings, I defined the new story board for iPhone, in Portrait mode. In the new storyboard, I changed every viewController to set in Portrait mode.
When I launch the App on iPhone (simulator or device) It's still in landscape mode but with the changes (moved fields, for exemple) I made in the new storyboard.
Did I forget something?
Thanks :)
This started happening with the new xCode for universal projects... go to your .plist file for the project and you will find a field for orientation for iPad (1 item) and orientation for iPhone (4 items), expand the iphone one and remove the rows containing orientation you don't want. Save, clean, and build.
Don't search anymore, i found the solution.
In the app I've to access to the Camera Roll.
On the iPad, if I access it in landscape mode, the Camera Roll opens in Portrait, and it's ugly and annoying for the user.
Then someone on Stack suggested to use a Category UIViewController+OrientationFix.h
Here is the code...
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
I had to modify it
NSString *deviceType = [UIDevice currentDevice].model;
NSLog(#"Device Type : %#", deviceType);
if([deviceType hasPrefix:#"iPad"])
{
return UIInterfaceOrientationMaskLandscape;
}
else
return UIInterfaceOrientationMaskAll;
The strange thing it that I didn't found it by searching "landscape" in all the projet, even by ignoring case.
I would like to know how to disable Portrait and UpsideDown orientations in my app for iOS 5.1.1.
I want my app to use only LandScape orientation (interface was drawn in Interface Build in .xib file) and don't change it in case of rotation.
I need it especially for iOS 5.1.1
A similar question: how do you make an app ONLY support landscape?
This method was used in the answer above:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight)
return YES;
return NO;
}
You can set it in project settings. In xCode 5 you open the project navigator, click on your project, click on the general tab, and check the boxes you want.
Seems like a simple thing to do right? Go to the Target's Summary tab and set "Supported Interface Orientations" to Landscape Right only. You would think that would mean the app would be landscape only. But no.
On a device running 5.1 for example, if you open the app and hold the phone in the correct landscape right position you will see the view rotated 90 degrees counterclockwise, as if it think it's supposed to be in portrait mode, unless you add something like this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
But that only works for one view controller, and who knows if it works on all OS versions.
So how do you make an app landscape only? Do I have to add that code to every single view controller in the app? I do not need any rotation. All my views are designed in Landscape. I just want the app to open in Landscape Right mode and stay that way. And I want to support iOS 5 and up.
There are new methods introduced that you have to implement along with the old one they are as below
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
In Xcode you can navigate to your project settings -> summary -> iPhone/iPod deployment info. Here you can select the supported interface orientations. You can also edit the 'Supported interface orientations' array in your application's info.plist by adding the desired interface orientations application wide.
In the info.plist put the orientation to landscape