2012-10-23 58 views
0

我工作在通用應用程序,它工作正常,直到ios 5,但在ios 6中存在定位問題。我的應用程序只處於肖像模式。問題是當我的ipad處於橫向模式時,並且比開始我的應用程序的方向更改爲protrait時。所以請幫助我一些代碼,以便我強制我的應用只能在應用啓動之前獨立於設備的方向而處於專業模式定位問題在ios 6

+0

你能請將didFinishLaunchingWithOptions方法的代碼放在Appdelegate類 –

+0

中您爲IOS 6方向寫了什麼? – TheTiger

+0

http://stackoverflow.com/a/12651309/1059705 – Bala

回答

2

發生這種情況是因爲Apple已經改變了管理UIViewController方向的方式。在Ios6中,Oreintation處理方式不同。在iOS6容器(例如UINavigationController)中,不要諮詢子項以確定它們是否應該自動旋轉。默認情況下,應用程序和視圖控制器支持的界面方向設置爲UI成語的UIInterfaceOrientationMaskAll和iPhone成語的UIInterfaceOrientationMaskAllButUpsideDown。因此默認情況下,設備獲取方向已更改。

所以需要執行一些步驟。

1 - 設置所述取向從這裏

enter image description here

2 -place本規範中FirstViewController加入到RootViewController的

@implementation UINavigationController (RotationIn_IOS6) 
    //Here UINavigationController is the RootViewController added To the Window 

-(BOOL)shouldAutorotate 
{ 
return [[self.viewControllers lastObject] shouldAutorotate]; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return [[self.viewControllers lastObject] supportedInterfaceOrientations]; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; 
} 

@end 

**將下面的方法中的ViewController,在IOS6中引入允許修改**

- (BOOL)shouldAutorotate 
{ 

    return NO; 

    } 

/*Return the Number of Oreintation going to supported in device*/ 

- (NSUInteger)supportedInterfaceOrientations 
    { 
return (UIInterfaceOrientationMaskPortrait |  UIInterfaceOrientationMaskPortraitUpsideDown); 

} 

// Returns interface orientation masks. 

    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
    { 
     return (UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown  ) ; 

} 
+0

thnx代碼。我會盡快檢查 –

+0

Thnx兄弟代碼工作正常 –

+0

@The_code_cracker你歡迎.... !!!! – Kamarshad

0

在您的ViewController.m中,您必須定義支持的方向。在IOS 6中,這是處理支持的方向的方法。

- (NSUInteger)supportedInterfaceOrientations{ 
    return UIInterfaceOrientationMaskAll; 
} 

UIInterfaceOrientationMaskAll意味着它將支持所有view方向。

而且閱讀蘋果文檔 - Doc about Orientation

4

首先,我們必須設定在Targets->要點支撐取向...

在iOS6.0 shouldAutorotateToInterfaceOrientation方法是deprecated.So,採用這個方法,我們必須使用shouldAutorotate方法..

並與方法supportedInterfaceOrientations我們要設置我們要像UIInterfaceOrientationMaskAll其方位,如果我們希望所有的方位