2012-09-24 63 views
3

我在iOS 6的應用定位方面存在問題。即使設置爲「橫向(右側主頁按鈕)」和「橫向(左側主頁按鈕)」,它也會顯示爲「肖像「扭曲的應用程序。iOS6的定位問題

我一直在努力與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 

請幫幫我!謝謝!

回答

1

shouldAutorotateToInterfaceOrientation未在iOS 6中使用;請參閱UIViewController documentation頂部的「處理視圖旋轉」。沒有進一步的工作,你只會得到你在項目設置中提名的任何東西。

在iOS 5及更早版本,您已經有了:

return (interfaceOrientation == UIInterfaceOrientationPortrait); 

所以在這些系統上你明確地限制該視圖控制器爲縱向。

0

你需要在你的AppDelegate.mm文件中檢查這個。檢查是否存在以下代碼行

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

它不存在,只是添加它,但我仍然遇到同樣的問題。 – esierr1