2.x和1.x的设备方向设置有所不同,在网上找了下相关的方法,下边这个是最基本的设置方法:
原贴地址:http://120423319.blog.163.com/blog/static/278218242012102711104446/
一、
2.0开始木有1.0那套定义,那么修改横竖屏在AppDelegate.m文件中有如下代码
// Supported orientations: Landscape. Customize it for your own needs
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// 横屏可上下
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
// // 竖屏可上下
// return UIInterfaceOrientationIsPortrait(interfaceOrientation);
// // home键在下面
// return ((interfaceOrientation) == UIInterfaceOrientationPortrait);
// // home键在上面
// return ((interfaceOrientation) == UIDeviceOrientationPortraitUpsideDown);
// // home键在右边
// return ((interfaceOrientation) == UIDeviceOrientationLandscapeRight);
// // home键在左边
// return ((interfaceOrientation) == UIDeviceOrientationLandscapeLeft);
}
1.0貌似可以用如下代码
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
如果需要代码生效,请将 project-》TARGETS-》Summary-》support interface orientations 中所有的屏幕方向点击设定无效,否则代码会失效。很重要的是这里ios6实测,就算这样设定后,在一些情况下屏幕方向设定还是有BUG。
二、
如果要让设备竖直显示,HOME键朝下的话,按照上述方法设置后,其实程序还是报错,提示:
‘Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES’
-(NSUInteger)supportedInterfaceOrientations {
// iPhone only
if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone )
return UIInterfaceOrientationMaskLandscape;
// iPad only
return UIInterfaceOrientationMaskPortrait; //修改此处,将此处修改为UIInterfaceOrientationMaskPortrait
}
这样程序便能正常的竖直显示..