How do I make landscape cocos2d v2.0 games on ios6? - ios

I had been working on a couple of games from a few months back. I migrated them to cocos2d v2.0 just fine but yesterday I tried creating a new one and I get it only in portrait no matter what I do to the Target settings rotations.
How can I make my new game landscape?

Search for supportedInterfaceOrientations function in AppDelegate class and change it to landscape. If this function not found then add it.
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}

I just fixed it by changing the addSubview line:
[window_ addSubview:navController_.view];
to
[window_ setRootViewController:navController_];
wonder why

Related

Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES' in xamarin iOS

My app supports only landscape mode. when i am trying to open image picker within the app it shows an exception which is as follows:
"Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES"
I had tried to make false value for shouldAutorotate but didn't succeed. I am stuck with this. Any one have any help regarding this?
If you like to use UIImagePickerController as lanndscape mode , instead of
- (BOOL)shouldAutorotate
{
return NO;
}
use this
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
but make sure to check this as:

How to create a landscape-view only ios application

I want to create an iOS app that can only work on landscape-view mode.
I Googled how to do that, and end up with supportedInterfaceOrientations method
Here's my attempt:
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft;
}
I tried to put the above code on viewController.m and AppDelegate.m, but it didn't seem to work
Thanks, any opinion will be much appreciated
You don't need to write any code to run app which supports landscape mode only. Just select app target and uncheck portrait and portrait upside down orientation and make sure landscape orientation is checked.
It seems as though you want to programmatically change the orientation of your application. This can be done by any ViewController by implementing one method.
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
That should force the view to auto-rotate in the direction you want it.
When you use -supportedInterfaceOrientationForPresentation it simply states that the returned interfaces can be used, not necessarily that they should be used.
When you use -preferredInterfaceOrientationForPresentation it says that this is orientation that I want, and that the ViewController should switch to it.

GameCenter authentication in landscape-only app throws UIApplicationInvalidInterfaceOrientation

Problem:
If user is not logged into GameCenter account - GameCenter authentication view is launched in portrait mode (in ios 5 there were a modal dialog) asking to log in. But if I disable Portrait mode in xcode (Project Summary) or in supportedInterfaceOrientationsForWindow: (as my app supposed to run in landscape mode ONLY) I get:
Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'
If I enable Portrait for ipad/iphone (and/or comment out supportedInterfaceOrientationsForWindow:) it works without crash, but I don't want portrait mode to be enabled.
While writing this question and experimenting with code, it seems that I've found a solution:
enable all orientations in project summary and remove application:supportedInterfaceOrientationsForWindow.
Add this code to ViewController:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
Now it works seamlessly.
Add to app delegate:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)w {
return (NSUInteger)[application supportedInterfaceOrientationsForWindow:w] | (1<<UIInterfaceOrientationPortrait);
}
I have found that the problem is coming from the Game Center in my case. When in the simulator I do not have the Game Center initialized yet, it would like to pop up the login view, but in portrait mode. Once it is reaching this point it crashes if I disallowed portrait orientation. Strange bug in the OS as Game Center should take the allowed orientations only to be inline with our intention of landscape user interface.
I do not have the solution yet, but I will post if I find it.
I had the same issue as you and I fixed it with a kinda, ugly work around, basically I have a global variable in my app that I use to choose what the valid interface orientations are. In the
- (NSInteger)application : (UIApplication *)supportedInterfaceOrientationsForWindow:(UIWindow *)window{
if(orientationIndicator == 1){
return UIInterfaceOrientationMaskAllButUpsideDown;
}
else if(orientationIndicator == 2){
return UIInterfaceOrientationMaskLandscape;
}
}
To declare the global variable put this in your appDelegate.m file :
int orientationIndicator = 1;
To import the global variable use :
extern int orientationIndicator;
Then you can change the value of orientation indicator and it will allow you to run in different interface types. So what I did was I start by making the orientationIndicator = 1. When you authenticate a player and initiate the login view controller set the orientation indicator to 2. When you dismiss the view (authenticate the player) then you can change it back to 1.
This is a slimy work around but it has worked for me.
Hope this helps!
Catching the exception appears to work just fine for me:
#try {
[rootNavigationController pushViewController:viewController animated:YES];
}
#catch (NSException *exception) {
//somehow, catching this exception just allows the view controller to be shown?
}
In iOS 6.0, the exception is thrown, but if you catch it then the viewController will still be shown and GameCenter will behave as expected in landscape orientation.
An alternate solution is just to target iOS 6.1 and above, as Apple fixed the bug by that release.

AS3 iOS prevent "animated" orientation change

I am working in flash CS5.5 on an app for iOS. I want to get the ipad/iphone to stop animating the orientationChange and just change it directly, is this possible?
I thought this was a solution but it didnt help AS3 - iOS force landscape mode only?.
If you try setting Stage.autoOrients = false;, the flash.events.StageOrientationEvent.ORIENTATION_CHANGE will never fire. That's helpful for disabling orientation changes altogether, but not for your issue. While I haven't tried it myself, you may be able to listen to the event:
flash.events.StageOrientationEvent.ORIENTATION_CHANGING
You may be able to call event.preventDefault() in that listener to stop the actual rotation from occuring. Then you can manually set it yourself:
Stage.setOrientation(StageOrientation.ROTATED_RIGHT);
have you tried the SO answer: Disable orienation change rotation animation ?
the code from that answer that goes in the view-controller that is the home for your flash CS5.5 or air 3.5 is:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[UIView setAnimationsEnabled:YES];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
[UIView setAnimationsEnabled:NO];
return TRUE; /* Your original orientation booleans, in case you prevent one of the orientations */
}
that code makes use of native iOS UIViewController functions that can be overridden. you would have to have a native iOS objective C class that overrides UIViewController, and then you could insert the code above. calls are made when the device is rotated to these as part of view controller life cycle.

iPad 2 UIImagePickerController camera auto-rotation driving me mad!

I've been trying to sort this one out for a while and getting nowhere.
I'm using the camera on the iPad 2 - my application is in landscape, but I want to use the camera in portrait mode. I just can't seem to force the ImagePicker a, into Portrait mode, and b, to stop auto-rotating.
Is there any way that you can force the ImagePicker into portrait (or landscape), and/or to stop it auto-rotating?
Even though the App is in landscape and is set to return YES only to landscape orientations, the ImagePicker ignores that and rotates into portrait when you rotate the iPad 2.
If I could force it into staying in landscape then (although not ideal) I could re-design the app to use the camera in landscape, but I don't seem to be able to do even that!
Any help greatly appreciated!
The method that you need to override called:
_isSupportedInterfaceOrientation:
So it should look something like this :
#interface PortraitImagePickerController : UIImagePickerController {
}
#end
#implementation PortraitImagePickerController
- (BOOL)_isSupportedInterfaceOrientation:(UIDeviceOrientation)orientation{
return UIDeviceOrientationIsPortrait(orientation);
}
#end
But it's definitely private method so Apple may reject your app
Well i have found a more convenient way and has no risk of using private code.
Sub class a UIImagePickerController and add following method in its .m file.
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}

Resources