Universal app orientation issue - ios

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.

Related

Force a UIViewController just landscape in iOS 9

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

iOS+SpriteKit: How to force portrait mode?

I'm currently working on a SpriteKit game for iOS 7+ and XCode 6. The game should always be presented in portrait mode. So far I have implemented these methods in my view controller:
- (BOOL)shouldAutorotate {
return NO;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
This works fine as long as I start the app holding my iPad in portrait mode. It does not switch the orientation during game play.
But when holding the iPad in landscape orientation during the app is starting, the game is shown in landscape.
How do I force the app to be shown in portrait mode even if the device was held in landscape mode during startup ?
To solve the app orientation issue
Go to your projects plist file (should be "YourApp-Info.plist")
Add a row and enter "Supported interface orientations"
Add the orientations that your app supports

Supporting certain orientations only not working in iOS 7?

I can't simply uncheck in the Deployment Orientation section because i have a view that must be viewed in landscape mode, and when I leave landscape mode unchecked while it works in the first few view to keep my views only portrait, when I get to the view that forces it to be landscape it crashes.
So with that being said, all orientation possibilities are checked on the Deployment Information and I am using the following code to keep my views portrait:
- (NSUInteger) supportedInterfaceOrientations {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}
else
{
return UIInterfaceOrientationMaskAll;
}
}
The problem is, that this does not seem to be working in iOS 7, or in the iOS 6 simulator for that matter, although it works well in my physical iPhone with iOS 6, but again, not on the iPhone with iOS 7.
What can be a solution to this problem?

Auto Detect Device Orientation

How to achieve the following functionalities in iphone app.
Always app launch portrait mode. if the simulator is landscape mode first launch in portrait mode then detect the device orientation change the app according to the current device orientation.
Either you can disable all orientations except portrait in your project and then set orientation programmatically throughout your app. Or you can stop orientation for specific view controller (may be in your case, viewcontroller during launching) by returning value NO. like this
- (BOOL)shouldAutorotate {
return NO;
}
and as mentioned by #Conner
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}

Universal app not rotating on iPad but does on iPhone

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.

Resources