UIViewController and Cocos2D in landscape mode ?

Forums Programming cocos2d support (graphics engine) UIViewController and Cocos2D in landscape mode ?

This topic contains 4 replies, has 4 voices, and was last updated by  marciokoko 1 year, 1 month ago.

Viewing 5 posts - 1 through 5 (of 5 total)
Author Posts
Author Posts
November 30, 2009 at 1:58 am #218623



I am not sure if this is actually a Cocos2D issue, but I try anyway, maybe someone has an idea.

I have an app using Cocos2D and want to make the help pages with html. Therefor I made created a WebViewController that inherits from UIViewController. So far so good, but what ever I tried I am not able to get this thing into landscape mode. I can use the shouldAutorotateToInterfaceOrientationmethod to allow roration (which works) but the WebViewController always starts up in portrait mode.

I also added UIInterfaceOrientation to the Info.plist, but nothing seems to help. I already found some links to undocumented API calls (I know, not a good idea at all) but even those did not work ?!

Heres the code I use to show the WebViewController:

WebViewController *web = [[WebViewController alloc] init];

[self showUIViewController:webViewController];

[webViewController loadHelp];
[[Director sharedDirector] pause];

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.5];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:[[Director sharedDirector] openGLView] cache:YES];

[[[Director sharedDirector] openGLView] addSubview:controller.view];

[UIView commitAnimations];

Does anyone has any idea how this work ?

November 30, 2009 at 6:35 am #267366


Hi, the design pattern that works for me is to use a CCLayer as the controller and to simply load the UIWebView… regardless, you can directly affect the orientation of this or any UIVIew by applying a transform:

webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
webView.transform = CGAffineTransformMakeRotation( CC_DEGREES_TO_RADIANS( 90.0f ) );
webView.bounds = CGRectMake(50, 10, 300, 200);


November 30, 2009 at 1:55 pm #267367


In my viewcontroller’s -viewDidLoad I put:

self.view.center = CGPointMake(160, 240);
self.view.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS( 90.0f ));

November 30, 2009 at 6:17 pm #267368


Thanks a lot, that works ;)

February 28, 2013 at 3:58 am #267369


I realize this was 3 years ago, but how would you do this in cocos2d v2?

I created a UIViewController with UIWebViewDelegate and iboutlet. I configured it to load the index.html i want.

But i get that showUIViewController and openGLView are both deprecated

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.