I have a couple of older Cocos2d games that, when updating, I noticed appear truncated upon launch. Having found other answers here on StackOverflow I am still having issues.
The workaround I currently use is;
Inside AppDelegate.m I am using
CGAffineTransform transform = CGAffineTransformMakeRotation(1.57079633);
navController_.view.transform = transform;
And setting the device orientation to Portrait & Portraitupsidedown - even though the game is Landscape.
This is a dirty fix, and brings it's own set of issues, such as UIAlert views not appearing at the correct orientation, as well as the screen not rotating landscape upside down (unless you hold it portraitupsidedown) which gets confusing, and pretty sure it is against Apple's review rules and just make the whole workaround useless really.
Effectively I need to trick it so that I can enable Landscape mode rather than Portrait, yet rotate the screen on launch, has anyone managed this successfully?
Add this in AppDelegate.m class
(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskLandscape;
}
Project file -> 'Targets' -> Choose you orientation to Landscape
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 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!
This is a strange issue that may be related to all the orientation issues I'm seeing in iOS8.
I have a universal app. The iPad version supports only landscape and the iPhone version supports only portrait.
When a user opens the iPad version, it opens in landscape mode, which is expected. However, every control on the right side of the view is unresponsive to user touch events. The affected area is 256 wide, and the area on the left that 'works' is 768 wide (portrait width). Therefore, even though the app opens in landscape, the app thinks it's in portrait. Since the phone version only supports portrait, the issue doesn't reveal itself there, though I believe the issue is not device specific, however, the issue only affects devices running iOS8.
The app was originally developed for iOS4 and has gone through several iterations since. However, much of the original code and nibs are still in use. Other orientation issues have shown up with iOS8 and could be related, or not, who knows?
Since the app was originally designed for iOS4, storyboards were not used, and still aren't. I have checked some things: made sure all nibs have 'Auto resize subviews' checked, and made sure that only landscape orientations existed in the app plist (verified in XML). Here is a code snippet from AppDelegate didFinishLaunchingWithOptions:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
[self.window setFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[AppMainViewController alloc] initWithNibName:nib bundle:nil];
//...
return YES;
}
In the image, I'm showing both portrait and landscape sizes. As I mentioned earlier, the view controller renders and looks as it should in landscape, but anything in the red area of the image is unresponsive to user taps.
Perhaps I've looked at this issue too long and hopefully somebody has some insight on why this is happening. Anyone? Thanks!
My app only supports landscape orientations via the supportedInterfaceOrientation properties.
Using an iOS prior to iOS 6, my app can successfully load an instance of UIImagePickerController via presentViewController:animated:completion: even though the UIImagePickerController itself only supports portrait orientation.
The image picker simply presented itself sideways to the user. The user rotated the phone, picked their image, and then rotated back to landscape.
Under iOS 6.0, calling presentViewController:animated:completion: with the UIImagePickerController instance crashes the app. I can prevent the crash by adding portrait options to my supportedInterfaceOrientation properties.
However, operating in portrait really does not make sense for my app. I had thought I could use shouldAutorotateToInterfaceOrientation to allow the app to "support portrait" but only be allowed to rotate to portrait in this one view. But now that method is deprecated, and I can't use the same technique with shouldAutorotate.
Does anyone have any ideas how I can get around this issue under iOS 6.0?
iOS 6.1 - fixed
As of iOS 6.1, this no longer occurs, it is very important to follow my tips in order to avoid a crash under iOS 6.0.x, the below still applies to that.
iOS 6.0.x workaround
This is in actual fact a bug in iOS 6.0, this should be fixed in future iOS releases.
An engineer from Apple has explained this bug and a workaround here: https://devforums.apple.com/message/731764
This is happening because the Application wants landscape orientation only but some Cocoa Touch View Controllers require strictly Portrait orientation which is the error - not that they should be requiring more then Portrait but their interpretation of the Applications requirements.
An example of this can be the following:
iPad app supporting landscape only displays a UIImagePickerController
via a UIPopoverController. The UIImagePickerController requires
Portrait orientation, but the app is forcing landscape only. Error
and... crash
Other frameworks that have been reported as problematic include the Game Center login view controller.
The workaround is pretty simple but not ideal... You keep the correct orientations declared in your info.plist/project info pane, but in the Application Delegate class you declare that you allow all orientations.
Now each View Controller you add to the window must specify itself that it can only be Landscape. Please check the link for more details.
I cannot stress how much you should not be subclassing UIImagePickerController as the accepted solution is insisting you do.
The important thing here is "This class is intended to be used as-is and does not support subclassing."
In my case I added this to my application's delegate (I have a landscape only app), this tells the image picker it can display, because portrait is supported:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskAll;
}
And then in my view controller which happened to be a UINavigationController, I included a category with the following:
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
Now my app doesn't rotate, and the image picker asks the delegate if it can display as portrait and it gets told that's okay. So all plays out well.
I had a similar issue, but in an iPad landscape app. I was presenting the image picker in a popover. It crashed under iOS 6. The error suggested that the picker wanted portrait, but the app only offered landscape views, and ... importantly ... the picker's shouldRotate was returning YES.
I added this to my ViewControllerClass.m that is creating the picker
#interface NonRotatingUIImagePickerController : UIImagePickerController
#end
#implementation NonRotatingUIImagePickerController
- (BOOL)shouldAutorotate
{
return NO;
}
#end
and then used that class instead
UIImagePickerController *imagePicker = [[NonRotatingUIImagePickerController alloc] init];
[myPopoverController setContentViewController:imagePicker animated:YES];
That solved the problem for me. Your situation is a bit different, but it sounds like fundamentally the same error.
While subclassing UIImagePickerController works, a category is a better solution:
#implementation UIImagePickerController (NonRotating)
- (BOOL)shouldAutorotate
{
return NO;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
#end
Reporting from iOS 7.1:
In addition to what the above answers specify it seems that you have to absolutely enable portrait modes in the info.plist.
Without this none of the above code/fixes worked for me.
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
Will fix the issue but from iOs7
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.