你可以参考这个:http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Device_Orientation
对于 ios:在 viewcontroller.m 中
bool shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// 横向
return UIInterfaceOrientationIsLandscape( interfaceOrientation );
// 肖像
return UIInterfaceOrientationIsPotrait( interfaceOrientation );
}
如果有多个:
bool shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation)||UIInterfaceOrientationIsLandscape(interfaceOrientation) ;
}
根据您的方向缩放内容:
void didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
CGSize s;
if (UIInterfaceOrientationIsLandscape(UIApplication.sharedApplication.statusBarOrientation))
{
s = CGSizeMake(std::max<float>(UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height),
std::min<float>(UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height));
}
else
{
s = CGSizeMake(std::min<float>(UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height),
std::max<float>(UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height));
}
CCDirector* director = cocos2d::CCDirector::sharedDirector();
director->enableRetinaDisplay(false);
director->getOpenGLView()->setFrameSize(s.width, s.height);
director->getOpenGLView()->setDesignResolutionSize(s.width, s.height, kResolutionShowAll);
director->enableRetinaDisplay(true);