2011-03-10 70 views
1

像往常一樣我有一個UIViewController的子類。當我加載應用程序時,我需要調整一些必須以編程方式放置的元素。當然,大小取決於接口方向:所以,我所做的:UIViewController interfaceOrientation問題

- (void)viewDidLoad { 
    switch([self interfaceOrientation]) { 
    case UIInterfaceOrientationPortrait: 
    case UIInterfaceOrientationPortraitUpsideDown: 
      NSLog(@"Portrait"); 
      break: 
    case UIInterfaceOrientationLandscapeLeft: 
    case UIInterfaceOrientationLandscapeRight: 
      NSLog(@"Landscape"); 
      break; 
    } 

但是,沒有模擬器/設備的方向的事情,情況總是肖像在viewDidLoad中/ WillAppear,即使一切正常旋轉。 在Plist中,我添加了所有支持的方向。 提示?

+0

碰到完全相同的問題!這在模擬器中一直是個問題。 最好的是:打破「willRotate」,它告訴你它會旋轉到風景。接下來它在layoutSubview中打破。如果你檢查那裏的方向,它是肖像! WTF? – Krumelur 2011-11-03 20:44:13

+0

難道你應該重寫'shouldAutorotateToInterfaceOrientation'並返回YES嗎?如果你這樣做,把你的代碼移到那個方法。 – Mazyod 2012-05-19 04:55:44

回答

8

嘗試[UIApplication sharedApplication].statusBarOrientation和交換機檢查UIDeviceOrientationPortraitUIDeviceOrientationPortraitUpsideDown等因爲[self interfaceOrientation]在我的經驗中是不可靠的。

+0

我從來沒有嘗試過使用statusBarOrientation。該設備的一個是無用的,因爲它告訴你,如果你把iPad放在桌子上。 – IssamTP 2011-04-01 18:49:33

+0

狀態欄提示保存了我的一天。 UISplitViewController總是返回prortrait。 – Krumelur 2011-04-13 10:20:34

+0

statusBarOrientation返回一個UIInterfaceOrientation(而不是UIDeviceOrientation),所以你應該使用UIInterfaceOrientationPortrait(),否則你偶爾會得到奇怪的結果。 – ToddH 2012-10-24 17:11:42

0

我正在處理iOS應用程序的旋轉和方向。我發現self.interfaceOrientation將永遠給你一個正確的結果,如果在viewDidAppear或之後調用。

[UIApplication sharedApplication] .statusBarOrientation應該是直接添加視圖到UIWindow的首選。

希望它有幫助。

相關問題