iPad发布方向 [英] iPad launch orientation

查看:99
本文介绍了iPad发布方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读了很多帖子之后,我仍然不知道如何解决这个问题...

After reading many posts, I still haven't got a clue how to solve this problem...

我的应用程序的第一个视图是tableViewController。我重写

The first view of my app is a tableViewController. I override

(BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation 

并且它总是返回YES。

and it always returns YES.

如果我在横向方向上直立iPad,它会在我启动应用程序后立即旋转。但是,如果我把我的iPad放在桌子上,即使我的主页是横向的,它也会以朝向的方向发射。

If I hold my iPad upright under landscape orientation, it rotates right after I launch the app. However, if I put my iPad flat on the table, even though my homepage is in landscape orientation, it launches in protrait orientation.

所以我想问题是,如何我可以获得我的主页的方向并以这个方向启动我的应用程序吗?

So I guess the problem is, how can I get the orientation of my homepage and launch my app with that orientation?

推荐答案

我的应用程序是openGL,但我的方式处理这是为了使用通知:

My app is openGL, but the way I handled this was to use notifications:

// 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在实际调用之前被调用开始旋转方向。

willRotateToInterfaceOrientation is called right BEFORE it actually starts rotating the orientation.

然后在我的EAGLView initWithFrame中:我设置观察者..

Then in my EAGLView initWithFrame: I set up observers..

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

在viewBecamePortrait和viewBecameLandscape中我以编程方式处理更改。

and in viewBecamePortrait and viewBecameLandscape I handle the changes programatically.

这篇关于iPad发布方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆