How to rotate cocos2D game into landscape mode in iOS 6? - iphone

I have an iPhone 4S (running iOS 5.1) & an iPhone 5 (running iOS 6.1). I noticed that when i try to open the cocos2D game, on the iPhone 4S running 5.1, the game is able to open perfectly fine in landscape mode.
However, when I try to open the same cocos2D game on my iPhone 5 running 6.1, the game is opened in portrait mode.
Is there any way that I can rotate the cocos2D game into landscape mode in the iPhone 5 running iOS 6.1.
Some extra notes:
The game is being pushed from a view controller in my test app.
Since I am pushing the game from an iOS app, I have to support portrait mode in the "Support Interface Orientations" section. (If I was just doing the game, I would just easily set the Support Interface Orientation to landscape left/landscape right)
I have also tried different methods such as for iOS 6 such as:
-(NSUInteger)supportedInterfaceOrientations
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
-(BOOL)shouldAutorotate
But it has given me different results when I tried those methods.
Ideally, I would like the app to be locked in the Portrait mode and game to be locked into Landscape mode.
So, I'm wondering if it is possible to have an app that remains locked in the portrait mode and the game locked in landscape mode (for both iOS 5 & iOS 6) when opened?
Here's a link to a sample project I was working on:
http://www.4shared.com/zip/yEAA1D_N/MyNinjaGame.html

I just set the orientation modes in Xcode ("Summary" tab on your target) to landscape left and right. Then for every UIViewController I added this:
// Autorotation iOS5 + iOS6
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}

What I'm doing for landscape in my cocos2d game (on iOS 6.1):
//This is in the AppDelegate.m
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
//change to 'return UIInterfaceOrientationIsPortrait(interfaceOrientation);' for portrait
}

Related

Rotation works in iOS6 but not in iOS5

I am developing an app that supports iOS 5 & 6 and it is set up to run in Landscape Mode Right only, this is working pretty well under iOS 6 - but as soon as I run it in the iOS 5 Simulator the complete View is some kind of stretched in Portrait Mode, even if the Simulator is turned into Landscape Orientation - it's just the View...
iOS5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
iOS6
-(BOOL) shouldAutorotate{
return YES;
}
Note: If you are supporting both versions then you should add both of the methods, they will be called according to the version you are running on your device/simulator.
It is good idea to add the method for supported orientations
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape ;
}

UIWebView - YouTube Video Landscape mode - iOS6

I want to play a YouTube Video in a UIWebView in fullscreen (Landscape mode)
But all my other views to be only in Portrait mode. How is it possible that only the YouTube video is in landscape mode?
Do I have to enable the landscape mode in the app targets summary?
Thanks for help! :-)
If your app is using multiple orientations then you need to define them in the Project Target summary. e.g Portrait, Landscape left & Landscape right.
If you are having your device working for iOS5, use the following method(deprecated in iOS6) for rotating to particular orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
If you are having your device working on iOS6. you should use the following methods.
– shouldAutorotate – supportedInterfaceOrientations & – preferredInterfaceOrientationForPresentation
If your app supporting both versions then you could keep the both methods and check if your view controller is responding to the particular method by
if ([self respondsToSelector:#selector(methodToCheck)])
myTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
CGAffineTransform rotate = CGAffineTransformMakeRotation(1.57079633);
[myTableView setTransform:rotate];
self.view = myTableView;
This will also work*
make sure here i have done in tableview

iOS 6 orientation changes have me totally confused

This is a universal app and I have the supported interface orientations for both iPhone and iPad targets set only to Landscape Left and Right. My root view controllers do not use a NavigationController and the xibs are landscape oriented views. The app is designed to only use the landscape orientations.
In application:didFinishLaunchingWithOptions I have...
if (([JLHelper isIPhone]) | ([JLHelper iPadPortraitRestricted])) {
application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;
}
In iOS 5 everything worked fine but In iOS 6 the view does not display in a landscape orientation on startup.
I understand that shouldAutorotateToInterfaceOrientation has been deprecated in iOS 6, but I do not understand why this affects the initial presentation. It appears to me that the root view is being rotated.
I have read many discussions on how to force landscape orientation in iOS 6 and am now totally confused. There must be a simple way to implement an app that only uses landscape orientation.
You can specify the supported orientations in the info.plist for iOS 6. Additionally you can implement the shouldAutorotate method and the supportedInterfaceOrientations methods (new as of iOS 6) to conditionally restrict orientations for iOS 6.
Note that if you want to continue to support iOS 5 you also have to have the shouldAutorotateToInterfaceOrientation... method in place. iOS 5 uses the old method, iOS 6 the new one, they can coexist.

Event touch up inside work in iphone but dont work in ipad ios6

This generate the error
Generate a project for iphone only with orientation landscape left and landscape right
Add a button to the interface builder
Run on the ipad simulator
Press the button and it does not work.
What can i do?
This solved the problem for orientations in ios 6
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
Implementing the supportedInterfaceOrientations method in the ViewController does not help.
Kind of workaround would be to chose "Universal" (iPhone + iPad) as target device.

iPhone App with only portrait mode

How can i make my app to be always in portrait mode only. If i rotate iPhone it should not display app in landscape mode.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortrait);
return YES;
}
After this coding when i rotate iPhone app is displayed in landscape mode. How can i make app to be in portrait mode all the time.
Remove the method — you don't need it. An iPhone app always starts in portrait mode unless you force it to start in landscape mode. If this method is absent, it will stay in portrait mode, as it effectively means "My view won't respond to interface orientation changes."
Incidentally, this method actually starts out commented out in Xcode's view controller templates, which is the same as it not being there at all.
In xcode click left top on your project name and then right below of "TARGETS" you can set "Supported Device Orientations".
Seems for iOS 6 you need to override this method,
-(BOOL)shouldAutorotate {
return NO;
}