2010-05-18 49 views
2

閱讀很多帖子後,我還沒有得到一個線索是如何解決這個問題?iPad的推出方向

我的應用程序的第一個觀點是tableViewController。我覆蓋

(BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation 

它總是返回YES。

如果我在垂直方向上將我的iPad保持在橫向方向下,它會在我啓動應用程序後立即旋轉。但是,如果我將iPad平放在桌面上,即使我的主頁處於橫向,它也會以橫線方向啓動。

所以我想問題是,我怎麼能得到我的主頁的方向,並啓動我的應用程序的方向?

+0

我有同樣的問題,這解決了[iOS 5的設備取向] [1] [1]:HTTP ://stackoverflow.com/questions/9683658/notification-banner-on-ipad-displayed-upside-down-when-app-is-launching-landscap/11184749#11184749 – nikhilgohil11 2012-06-25 07:05:44

回答

1

我有這個相同的問題。有一些時髦的東西與你添加到窗口的第一個視圖控制器以及它的任何方向有關。確保視圖控制器全部爲方向,如果你想在最前面的一個與正確的方向

1

我的應用程序是openGL的打開返回是的,但我處理這個問題的方法是使用通知:

// Override to allow orientations other than the default portrait orientation. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return YES; 
} 

// This is called right BEFORE the view is about to rotate. Here I'm using a notification message 
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 

    if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) { 
     NSNotification* notification = [NSNotification notificationWithName:@"orientationIsPortrait" object:self]; 
     [[NSNotificationCenter defaultCenter] postNotification:notification]; 
    } 
    else { 
     NSNotification* notification = [NSNotification notificationWithName:@"orientationIsLandscape" object:self]; 
     [[NSNotificationCenter defaultCenter] postNotification:notification]; 
    } 

} 

在實際開始旋轉方向之前,將調用willRotateToInterfaceOrientation。

然後在我的EAGLView initWithFrame:方法我設置了觀察..

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewBecamePortrait:) name:@"orientationIsPortrait" object:nil]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewBecameLandscape:) name:@"orientationIsLandscape" object:nil]; 

和viewBecamePortrait和viewBecameLandscape我編程處理的變化。

0

在應用程序啓動時,只有在「主屏幕」處於橫向模式時纔會使用willRotateToInterfaceOrientation。 通過這種方式,我們可以在設備「正面朝上」或「面朝下」時檢測方向。 [UIDevice currentDevice] .orientation在情況下工作,如果設備不平行於地面。

0

我使用了狀態欄取向來使我openglview,像這樣:

UIDeviceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;  
NSLog(@"%s: orientation: %i", _cmd, (int)orientation);