Cocos2d screen By default is a horizontal screen, modified to vertical screen method

Source: Internet
Author: User
Tags bool uikit

In the rootviewcontroller.m file, modify the following code

Method of Shouldautorotatetointerfaceorientation

-(BOOL) Shouldautorotatetointerfaceorientation: (uiinterfaceorientation) interfaceorientation {////There is 2 ways t  o support auto-rotation://-the opengl/cocos2d to//-Faster, but doesn ' t rotate the UIKit objects//-the Viewcontroller-A bit slower, but the UiKit objects is placed in the right place//#if game_autorotation
	==kgameautorotationnone////Eaglview won ' t be autorotated.
	Since This method should return yes to least 1 orientation,///We return Yes only in the Portrait orientation//
	
return (interfaceorientation = = uiinterfaceorientationportrait); #elif game_autorotation==kgameautorotationccdirector////Eaglview'll be rotated by cocos2d////Sample:autorotat E only in landscape mode//if (interfaceorientation = = uiinterfaceorientationlandscapeleft) {[[Ccdirector Shareddir
	Ector] setdeviceorientation:kccdeviceorientationlandscaperight]; } else if (interfaceorientation = = Uiinterfaceorientationlandscaperight) {[[Ccdirector shareddirector] setdeviceorientation:kccdeviceorientationlandscapeleft]; 
	}//Since This method should return yes to least 1 orientation,///We return Yes only in the Portrait orientation
	
return (interfaceorientation = = uiinterfaceorientationportrait);
	#elif game_autorotation = = Kgameautorotationuiviewcontroller////Eaglview would be is rotated by the Uiviewcontroller// Sample:autorotate only in LANDSCPE mode////return YES for the supported orientations//Cross screen//return (Uiinterf
	 Aceorientationislandscape (interfaceorientation)); 
	
Return (uiinterfaceorientationisportrait (interfaceorientation));//Screen #else #error Unknown value in Game_autorotation
#endif//game_autorotation//Shold not happen return NO;
 }


//

There is 2 ways to support auto-rotation:

-The Opengl/cocos2d

-Faster, but doesn ' t rotate the UIKit objects

-The Viewcontroller

-A bit slower, but the UiKit objects is placed in the right place

//

#if Game_autorotation==kgameautorotationnone

//

Eaglview won ' t be autorotated.

Since This method should return YES least 1 orientation,

We return YES only in the Portrait orientation

//

return (interfaceorientation = = uiinterfaceorientationportrait);

#elif Game_autorotation==kgameautorotationccdirector

//

Eaglview'll be rotated by cocos2d

//

Sample:autorotate only in landscape mode

//

if (interfaceorientation = = Uiinterfaceorientationlandscapeleft) {

[[Ccdirector Shareddirector] setdeviceorientation:kccdeviceorientationlandscaperight];

} else if (interfaceorientation = = uiinterfaceorientationlandscaperight) {

[[Ccdirector Shareddirector] setdeviceorientation:kccdeviceorientationlandscapeleft];

}

Since This method should return YES least 1 orientation,

We return YES only in the Portrait orientation

return (interfaceorientation = = uiinterfaceorientationportrait);

#elif Game_autorotation = = Kgameautorotationuiviewcontroller

//

Eaglview'll be rotated by the Uiviewcontroller

//

Sample:autorotate only in LANDSCPE mode

//

Return YES for the supported orientations

Return (Uiinterfaceorientationislandscape (interfaceorientation));

Return (uiinterfaceorientationisportrait (interfaceorientation));

#else

#error Unknown value in Game_autorotation

#endif//Game_autorotation

Shold not happen

return NO;

}

-(BOOL) Shouldautorotatetointerfaceorientation: (uiinterfaceorientation) interfaceorientation {

//

There is 2 ways to support auto-rotation:

-The Opengl/cocos2d

-Faster, but doesn ' t rotate the UIKit objects

-The Viewcontroller

-A bit slower, but the UiKit objects is placed in the right place

//

#if Game_autorotation==kgameautorotationnone

//

Eaglview won ' t be autorotated.

Since This method should return YES least 1 orientation,

We return YES only in the Portrait orientation

//

return (interfaceorientation = = uiinterfaceorientationportrait);

#elif Game_autorotation==kgameautorotationccdirector

//

Eaglview'll be rotated by cocos2d

//

Sample:autorotate only in landscape mode

//

if (interfaceorientation = = Uiinterfaceorientationlandscapeleft) {

[[Ccdirector Shareddirector] setdeviceorientation:kccdeviceorientationlandscaperight];

} else if (interfaceorientation = = uiinterfaceorientationlandscaperight) {

[[Ccdirector Shareddirector] setdeviceorientation:kccdeviceorientationlandscapeleft];

}

Since This method should return YES least 1 orientation,

We return YES only in the Portrait orientation

return (interfaceorientation = = uiinterfaceorientationportrait);

#elif Game_autorotation = = Kgameautorotationuiviewcontroller

//

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.