2012-10-07 40 views
2

這是在我的AppDelegate中,並在方向更改上運行。當應用程序加載它時總是作爲肖像模式加載。如果我在設備處於橫向模式時加載應用程序,則仍會執行,就好像設備處於縱向模式一樣。這是我的第一個問題。第二是負載後,當我從縱向旋轉設備的風景,我收到了斷線的記譜如下:AppDelegate中的方向檢測

-(void)setOrientationView 
{ 

    UIDevice *currentDevice = [UIDevice currentDevice]; 
    [currentDevice endGeneratingDeviceOrientationNotifications]; 
    UIDeviceOrientation theOr = currentDevice.orientation; 

    if (UIDeviceOrientationIsLandscape(theOr) && !isLandVisible) 
    { 
     NSLog(@"setLand"); 
     isLandVisible = YES; 
     isPortVisible = NO; 

     [self.window.rootViewController pushViewController:portCont animated:YES]; // <Thread 1: breakpoint 2.1 

    } 

    if(UIDeviceOrientationIsPortrait(theOr) && !isPortVisible) 
    { 
     NSLog(@"setPort"); 
     isPortVisible = YES; 
     isLandVisible = NO; 

     [self.window.rootViewController pushViewController:portCont animated:YES]; 

    } 
    [currentDevice beginGeneratingDeviceOrientationNotifications]; 

} 

我拉我的頭髮試圖支持負載兩個方向,用故事板的應用,並且在查看它們之後不必關閉視圖(對於防止重新加載UIWebViews是必需的)。所以有兩個問題超出了我的視野。感謝所以。

+1

這是標準的行爲,應用程序加載肖像模式,而不是你的錯。 –

+1

這可能是這樣做的方式,但我不會在我的應用程序中這樣做,而只能在兩種橫向模式下運行。我在目標配置(在其中選擇方向)執行一些工作,其餘部分在rootViewController中完成。確保支持iOS 6和iOS 5,因爲它們不同。 –

+0

我甚至在通過rootViewController啓動加速度計時鎖定方向,它一切正常,所以我不會考慮AppDelegate,我自己。 –

回答

0

的iOS應用程序編程指南的Advanced App Tricks部分有大約Launching in Landscape Mode一些指引,這可能是因爲你的答案就在於那些幾行內(如果可能的話)。特別注意您的Info.plist文件中的UIInterfaceOrientation