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!
Related
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
I have an iPhone application who need to run on iOS 7 and iOS 8. It's a full Portrait Application, except for the video player who is displayed thanks to a presented ViewController.
When I start the application from the landscape mode on an iPhone 6 or 6 Plus, It will cause to destroy the HomeView. All the orientation are supported in the project because of the video player (I know I can avoid the problem by removing the landscape support but my video player won't be displayed properly).
So the question is : How can I do to start my application from landscape mode without break the HomeView (so in a nice portrait mode) but at the same time still have my video player properly displayed in landscape mode ?
PS : I can't post screenshots, so when I say "destroy", just imagine the view with not well positioned and scaled elements.
How can I do to start my application from landscape mode without break the HomeView (so in a nice portrait mode) but at the same time still have my video player properly displayed in landscape mode ?
How the application is oriented on launch depends on the order in which the supported orientations are listed in the Info.plist file. Just make sure that Portrait comes first.
How the home view can be oriented depends on the root view controller's implementation of supportedInterfaceOrientation. Make sure that it returns UIInterfaceOrientationMaskPortrait.
In Info.plist set device orientation just to Portrait
In AppDelegate add -
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskAll;
}
I have 2 root view controllers ViewController1 and TabBarController1(there are reasons for making 2 root view-controllers). ViewController1 only supports Portrait mode and TabBarController1 supports all orientations. ViewController1 appears first after launch. I am locking the orientation of ViewController1 using the following method.
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
The app launch and orientation worked fine with iOS7.
When building the app through Xcode 6 in iPad(iOS8) following change is observed:
- When app is launched in landscape mode, ViewController1 with orientation locked into portrait mode appears with half black screen and when TabBarController1 appears which supports all orientations, doesn't resize with proper dimensions on changing orientations.
I have also tried overriding the above method in TabBarController1 to support all orientation but nothing works fine.
This problem is not observed when launching the app on iPad in portrait mode.
There is no problem when launching the app on iPhone as iPhone launches only in Portrait mode.
What is the issue when working with iOS8 ?
I am a newbie, so don't judge..
In ios8, apple changed 2 things :
1-
[[UIscreen mainscreen] bounds].size
This used to be a fixed value for portrait and landscape, now it is not.
When u change from landscape to portrait the width and height switch.
2-What is happening with you. You cannot force a viewcontroller to be in portrait only if you set portrait and landscape in project settings, do not know why, so you maybe have to set portrait only in project settings for example..
This is happening on iPads and iphone 6+ only.
Hope this helped..
This question is a little strange. In Adobe AIR I am trying to combine an iPhone and an iPad version of my app into one single app. However i have a hard time dealing with orientation. I need the app on iPad to appear in landscape mode and on the iPhone it should appear in portrait mode.
Can this be done?
in shouldAutorotateToInterfaceOrientation do this
But don't forget to adjust view accordingly (set appropriate frames to subView)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
else
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
The first problem is detecting whether the device is an iPad or iPhone. I believe the only way to do this is by checking the device resolution (of course, you can distribute separate binaries for the different devices, but you mentioned doing this in one app).
Usually you can handle screen rotation in the XML app descriptor, e.g.:
<aspectRatio>landscape</aspectRatio>
<autoOrients>false</autoOrients>
However, since you want to do different actions depending on the device, this won't work.
An alternative that I have used in the past is to detect Orientation events and prevent the default and manually set the orientation through AS3. Here is a good example of how to do this: AS3 - iOS force landscape mode only?
Using the code sample presented there, it's just a matter of taking your device detection / screen resolution detection code and setting the screen orientation to the appropriate detection for that device (and preventing the appropriate orientation events for that device).
In case you still need it, I made the adaptation of the "force landscape mode only" to do the same with portrait only. Here's the code:
var startOrientation:String = stage.orientation;
if ( startOrientation == StageOrientation.ROTATED_RIGHT)
{
stage.setOrientation(StageOrientation.UPSIDE_DOWN);
}else if(startOrientation == StageOrientation.ROTATED_LEFT){
StageOrientation.DEFAULT;
}
else
{
stage.setOrientation(startOrientation);
}
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChangeListener);
function orientationChangeListener(e:StageOrientationEvent)
{
if (e.afterOrientation == StageOrientation.ROTATED_RIGHT || e.afterOrientation == StageOrientation.ROTATED_LEFT )
{
e.preventDefault();
}
}
I searched for other existing posts, but none of them satisfied my requirements.
Here is the problem i face,
My app supports both the Modes , landscape and portrait.
But my first screen only supports Landscape , so the app must start in Landscape.
I have set supported Orientation to all the 4 options
I have set the Initial interface orientation to Landscape (left home button)
In the view controller of the first screen i am defining the below
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortrait);
}
And when i start the app the simulator always opens in Portrait and my view is all messed up in the portrait mode , since it is designed only for the landscape.
After the switch to the Landscape, the device remains in this mode.
can anyone help me with the solution to avoid this ?
Thanks
Naveen
EDITED :
This info may be helpful , The problem is faced only when i hold the device in Portrait and then launch the app.
Its not the duplication of this question, Landscape Mode ONLY for iPhone or iPad
Landscape Mode ONLY for iPhone or iPad
I do not want my app to be only in Landscape , i want only the first screen of my app to be only in Landscape.
I did some experimenting with an app I'm working on that has the same requirements, and came up with the following:
To set the initial orientations that are supported when the app is first launched, use the "Supported Device Orientations" setting for your target.
Also back that up with the appropriate shouldAutorotateToInterfaceOrientation code, as you've already done.
For subsequent screens, simply use the shouldAutorotateToInterfaceOrientation code to determine which orientations you want to support. Even if you've specified only landscape modes for the Supported Device Orientation, shouldAutorotateToInterfaceOrientation wins. :)
I think this approach is a little cleaner than using an extra dummy VC.
I achieved a workaround for the Problem and it solved ,
I created a dummy view controller and added as the root view controller of the Window.
Added the below method in the implementation
-(void)viewDidAppear:(BOOL)animated
{
WelcomeScreen *welcomeScreen = [[[WelcomeScreen alloc] initWithNibName:#"WelcomeScreen" bundle:nil] autorelease];
[self presentModalViewController:welcomeScreen animated:NO];
}
Now it worked as expected.
Here is a SO link that will hopefully answer your question on how to launch your app in landscape mode.