2

看了很多帖子,还是不知道怎么解决这个问题……

我的应用程序的第一个视图是 tableViewController。我覆盖

(BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation 

它总是返回YES。

如果我在横向模式下将 iPad 直立放置,它会在我启动应用程序后立即旋转。但是,如果我将 iPad 平放在桌子上,即使我的主页是横向的,它也会以纵向启动。

所以我想问题是,我怎样才能获得主页的方向并以该方向启动我的应用程序?

4

4 回答 4

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 中,我以编程方式处理更改。

于 2010-07-14T17:02:26.010 回答
1

我有同样的问题。添加到窗口的第一个视图控制器以及它具有的任何方向都会发生一些时髦的事情。如果您希望第一个以正确的方向打开,请确保视图控制器都为方向返回 YES

于 2010-07-02T21:26:00.660 回答
0

在应用程序启动时 willRotateToInterfaceOrientation 仅在“主”屏幕处于横向模式时使用。这样我们就可以在设备“面朝上”或“面朝下”时检测方向。[UIDevice currentDevice].orientation 在设备不与地面平行的情况下起作用。

于 2010-11-26T15:06:15.430 回答
0

我使用状态栏方向来定位我的 openglview,如下所示:

UIDeviceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;       
NSLog(@"%s: orientation: %i", _cmd, (int)orientation); 
于 2010-12-28T12:13:55.503 回答