Allow only landscape mode in iOS app - ios

I read up Landscape Mode ONLY for iPhone or iPad and followed the steps, the app opens up in landscape mode but whenever i reallocate the view, it again comes up in the portrait mode. I have kept Landscape right as the only supported resolution and have overridden the souldAutoRotateToInterfaceOrientation as well. I am working on iOS 5.1.
Thanks.
Code:
-(BOOL) shouldAutoRotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

Related

ViewController orientation on external monitor

I have an iPad kiosk app that displays video on an external monitor connected via an HDMI cable. The device orientation is set to Landscape Left or Landscape Right in the apps general settings. I want the app to be displayed in landscape on the iPad and on the external monitor. When I run the app in iOS7 the external monitors view controller is displayed correctly in landscape orientation, but when run under iOS 8 the external monitor's view controller is rotated 90 degrees counterclockwise, into portrait orientation.
How do I force the external monitor to the correct landscape orientation? What has changed between iOS 7 and 8 to cause this behavior?
I've had a similar issue with a landscape-only iPad app that supports airplay. On the iPad screen, everything was working fine, but on the external display, starting # iOS 8.0, orientation issues started happening. I tried many things, what ended up helping was these two fixes:
On the shouldAutorotate method of your ViewController, return NO.
Implement the application:supportedInterfaceOrientationsForWindow: method:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)_window
{
if ([UIScreen mainScreen] == _window.screen || !_window)
{
return UIInterfaceOrientationMaskAll;
}
else
{
return UIInterfaceOrientationMaskPortrait;
}
}
The second part of the fix may require some changes on your side, since you're not using AirPlay, but I hope it can help lead you to the right solution. Good Luck!

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

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;
}

Iphone app is working fine in both landscape and portrait mode but in ipad it only works in one mode?

I made an ios app which is working fine in the iPhone in both mode either it is landscape or portrait by using the autorotation methods i used the following code
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
self.view=Landscape;
self.view.transform=CGAffineTransformMakeRotation(deg2rad* (90));
self.view.bounds=CGRectMake(0.0,0.0,480.0,320.0);
} else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
self.view=Landscape;
self.view.transform=CGAffineTransformMakeRotation(deg2rad* (-90));
self.view.bounds=CGRectMake(0.0,0.0,480.0,320.0);
} else if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
{
self.view=Portrait;
self.view.transform=CGAffineTransformMakeRotation(deg2rad* (0));
self.view.bounds=CGRectMake(0.0,0.0,320.0,480.0);
} else
{
self.view=Portrait;
self.view.transform=CGAffineTransformMakeRotation(deg2rad* (180));
self.view.bounds=CGRectMake(0.0,0.0,320.0,480.0);
}
}
But for the iPad its work only in one mode either landscape or portrait when i rotate the device it shows the blank white screen but if i don't rotate that it works pretty fine.
Kindly guide me as i am new to the iOS.
One place to check would be on the Application target, general tab, Deployment info section.
Just below the Deployment Target and Devices selectors, you can switch between iPhone and iPad, then enable supported orientations with the checkboxes.
If you already have these setup correctly for both iPad and iPhone, then you'll probably want to look at how you've handled the supportedInterfaceOrientations or possibly the preferredInterfaceOrientationForPresentation methods of your UIViewControllers

Launching app in landscape only mode

I've written an app that supports only landscape mode. For some reason, it is being very stubborn. It launches and runs great on the simulator, but when I go to launch it on my device, it will not launch or rotate to landscape mode at all. I'm running 5.1 on my iPad, and using Xcode 4.6.2. Here is everything I've tried after searching on this site for a solution:
Edited my -info.plist and deleted support for portrait mode in the supported orientation interface options
In the projects target, in the supported interface orientations I highlighted only landscape left and right
3 Added:
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
To my only ViewController file. It runs in landscape only on the simulator, but is being very difficult on my device. Does anyone have any ideas?
Check this tech note, it describes the opposite of your problem but the resolution is the same.

Resources