iOS6的定位问题

时间:2012-09-24 23:08:33

标签: xcode cocos2d-iphone uiinterfaceorientation

我的iOS 6应用程序方向存在问题。即使设置为“横向(右侧主页按钮)”和“横向(左侧主页按钮)”,它也会显示为“纵向”扭曲应用

我一直在尝试使用 RootViewController.m ,但没有运气!

这是代码,有人可以帮助我吗?

    @implementation RootViewController

    /*
    // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
    }
    */

    /*
    // Implement loadView to create a view hierarchy programmatically, without using a nib.
    - (void)loadView {
    }
    */


    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad {
[super viewDidLoad];
    }



    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

//
// There are 2 ways to support auto-rotation:
//  - The OpenGL / cocos2d way
//     - Faster, but doesn't rotate the UIKit objects
//  - The ViewController way
//    - A bit slower, but the UiKit objects are placed in the right place
//

    #if GAME_AUTOROTATION==kGameAutorotationNone
//
// EAGLView won't be autorotated.
// Since this method should return YES in at least 1 orientation, 
// we return YES only in the Portrait orientation
//
return ( interfaceOrientation == UIInterfaceOrientationPortrait );

    #elif GAME_AUTOROTATION==kGameAutorotationCCDirector
//
// EAGLView will 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 in at least 1 orientation, 
// we return YES only in the Portrait orientation
return ( interfaceOrientation == UIInterfaceOrientationPortrait );

    #elif GAME_AUTOROTATION == kGameAutorotationUIViewController
//
// EAGLView will be rotated by the UIViewController
//
// Sample: Autorotate only in landscpe mode
//
// return YES for the supported orientations

return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) );

    #else
    #error Unknown value in GAME_AUTOROTATION

    #endif // GAME_AUTOROTATION


// Shold not happen
return NO;
    }

    //
    // This callback only will be called when GAME_AUTOROTATION == kGameAutorotationUIViewController
    //
    #if GAME_AUTOROTATION == kGameAutorotationUIViewController
    -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
    {
//
// Assuming that the main window has the size of the screen
// BUG: This won't work if the EAGLView is not fullscreen
///
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGRect rect = CGRectZero;


if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)      
    rect = screenRect;

else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
    rect.size = CGSizeMake( screenRect.size.height, screenRect.size.width );

CCDirector *director = [CCDirector sharedDirector];
EAGLView *glView = [director openGLView];
float contentScaleFactor = [director contentScaleFactor];

if( contentScaleFactor != 1 ) {
    rect.size.width *= contentScaleFactor;
    rect.size.height *= contentScaleFactor;
}
glView.frame = rect;
    }
    #endif // GAME_AUTOROTATION == kGameAutorotationUIViewController


    - (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

   // Release any cached data, images, etc that aren't in use.
   }

   - (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
   }


 - (void)dealloc {
[super dealloc];
 }



 @end

请帮帮我!谢谢!

2 个答案:

答案 0 :(得分:1)

iOS 6中未使用

shouldAutorotateToInterfaceOrientation;请参阅UIViewController documentation顶部的“处理视图轮播”。如果没有进一步的工作,您将只获得项目设置中提名的任何内容。

在iOS 5及更早版本中,你有:

return ( interfaceOrientation == UIInterfaceOrientationPortrait );

因此,在这些系统上,您明确地将此视图控制器限制为纵向。

答案 1 :(得分:0)

您需要在AppDelegate.mm文件中检查这一点。检查以下代码行是否存在

// Supported orientations: Landscape. Customize it for your own needs
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
相关问题