2013-03-04 56 views
1

我有一個應用程序,其中包含5.0作爲部署目標,6.1作爲基本sdk,並且它在iOS 6.x設備/模擬器上運行良好。但在5.x上,我的觀點不是在旋轉。我搜索了一下,發現了一些Stackoverflow的帖子,但我不能找到正面和反面的一切。我想我需要實現我自己使用的不同視圖控制器的子類,但是哪一個是對的?爲什麼iOS 5的輪換在iOS 6下工作不起作用

在我的應用程序委託didFinishLaunchingWithOptions我使用它來創建我的應用程序:

self.tabBarController = [[UITabBarController alloc] init]; 
self.tabBarController.viewControllers = @[viewController1, viewController2, viewController3]; 
self.window.rootViewController = self.tabBarController; 
[self.window makeKeyAndVisible]; 

創建我viewController1 ..這樣的:

viewController1 = [[UINavigationController alloc] initWithRootViewController:[[SearchVC alloc] initWithNibName:@"SearchVC_iPhone" bundle:nil]]; 

我試圖在我的SearchVC_iPhone視圖控制器實現shouldAutorotateToInterfaceOrientation我已經嘗試在子類中繼承UINavigationController並實現shouldAutorotateToInterfaceOrientation,但它不適合我,我真的只是在這裏猜測。

請任何人都知道這個東西幫助我在這裏,我需要做什麼才能讓這個工作在iOS 5.x也?

謝謝
瑟倫

回答

1

我解決了它!問題是rootViewController,我必須在rootViewController上實現shouldAutorotateToInterfaceOrientation,然後所有子視圖開始按照他們應該的方式工作。所以我做了我自己的UITabBarController子類,它實現了shouldAutorotateToInterfaceOrientation並將其設置爲rootViewController。

+0

請設置你的問題。 – dhcdht 2013-03-04 11:49:07

2

在IOS5你可以使用

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
{ 
    return YES; 
} 

在iOS6的,你可以使用

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskAll; 
} 
+0

是的我試着在我的視圖控制器中實現shouldAutorotateToInterfaceOrientation,但我的視圖仍然不會在iOS 5.x中旋轉 – Neigaard 2013-03-04 10:03:58

0

我工作的一個應用程序(的Xcode 4.5的iOS 6) ,它必須與已安裝軟件版本的設備兼容,從4.5開始並默認使用iPhone 5.

我知道新的iOS 6更改自動旋轉模式。

當你打開你的設備「iPhone Simulator 6.0」應用程序的行爲正常,但當我在旋轉的方式運行「iPhone模擬器5.0」的問題。

我把代碼,以及從iOS 6和舊方法(不推薦)旋轉到iOS 5的新方法。

所以找旋轉方法:

{

if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) 

{ 

    //Code Here 

} 


if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) 

{ 

    //Code Here 

} 

return YES; 

}

#pragma mark - Rotate Methods iOS 6 
  • (無效)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 持續時間:(NSTimeInterval)持續時間

    {

如果(UIInterfaceOrientationIsPortrait(toInterfaceOrientation))

{ 

     //Code here 

    } 

如果(UIInterfaceOrientationIsLandscape(toInterfaceOrientation))

{ 

     //Code here 

    } 

}

相關問題