iPad 方向更改问题

发布于 2024-09-08 11:58:31 字数 785 浏览 1 评论 0原文

我的 iPhone 应用程序在 iPad 上运行时显示一些关于支持方向更改的奇怪行为。

该应用程序以视图控制器(为了论证起见,将其称为视图 A)和导航控制器启动,并且 shouldAutorotateToInterfaceOrientation 仅针对纵向返回 YES。在导航控制器上,我推送了一个视图控制器(视图 B),它也仅针对纵向返回 YES。然后,我将另一个视图控制器(视图 C)推到支持所有旋转的导航控制器上,并根据旋转方向调整屏幕上的项目。

当它在 iPhone 模拟器和设备上运行时,如果您在视图 C 上旋转到横向,然后点击后退按钮返回到视图 B,它会做正确的事情并将视图 B 切换回纵向模式。 (在模拟器中,它甚至自动将模拟器旋转回纵向。)

我遇到的问题是,当我在 iPad 模拟器和设备上执行完全相同的事件序列时,出现的视图 B 不会旋转回纵向,导航控制器仍然显示视图 C 的信息。然后,我点击后退按钮,视图保持不变,但导航控制器显示视图 B 的正常信息(但仍然处于横向模式)。然后,如果我再次点击后退按钮,视图 A 会出现在视图 B 导航栏项目下方,最后再次点击后退按钮会将我置于带有导航栏 A 项目的视图 A 上。

如果我在 iPad 上查看 B 并开始旋转,shouldAutorotateToInterfaceOrientation 将触发 NO,直到我进入纵向模式,然后一切恢复正常。

该应用程序是使用最新发布的 iPhone SDK 版本构建的,构建设置如下:iPhone Simulator 4.0 的基础 SDK、iPhone 的目标设备系列、iPhone OS 3.1.3 的 iPhone OS 部署目标。

有什么想法吗?

My iPhone application is displaying some odd behavior when run on the iPad with respect to supporting orientation changes.

The app starts up with a view controller (call it view A for the sake of argument) and navigation controller, and shouldAutorotateToInterfaceOrientation is returning YES for portrait only. Onto the navigation controller, I push a view controller (view B) that also returns YES for portrait only. Then, I push another view controller (view C) onto the nav controller that supports all rotations and adjusts the items on screen based on the orientation to rotate to.

When this is run on the iPhone simulator and device, if you rotate to landscape on view C and then tap the back button to return to view B, it does the right thing and shifts view B back to portrait mode. (In the simulator, it even rotates the simulator back to portrait automagically.)

The problem I am experiencing is that, when I do this exact same sequence of events on the iPad simulator and device, the view B that appears is not rotated back to portrait, and the nav controller still shows the information for view C. Then, I tap on the back button, and the view stays the same but the nav controller shows normal for view B (but all still in landscape mode). Then, if I tap the back button again, view A appears under the view B nav bar items, and finally tapping back again puts me on view A with nav bar A items.

If I go to view B on the iPad and start to rotate around, shouldAutorotateToInterfaceOrientation fires with NO until I reach portrait mode, and then all returns to normal.

The application is being built with the latest released version of the iPhone SDK, and has build settings as follows: Base SDK of iPhone Simulator 4.0, Targeted Device Family of iPhone, iPhone OS Deployment Target of iPhone OS 3.1.3.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

攀登最高峰 2024-09-15 11:58:31

苹果公司声明:

案例: UITabBarController 或 UINavigationController 中的所有子视图控制器在通用方向集上不一致。

响应:为了确保所有子视图控制器正确旋转,您必须为代表每个选项卡或导航级别的每个视图控制器实现shouldAutorotateToInterfaceOrientation。每个人都必须同意相同的方向才能发生旋转。也就是说,对于相同的方向位置,它们都应该返回 YES。

http://developer.apple.com/iphone/library/qa/ qa2010/qa1688.html

您可以在导航控制器中而不是在各个视图中设置设备方向。然后您可以检查堆栈上的视图并根据结果进行旋转。通过这种方式,导航控制器也可以处理所有方向。

Apple states:

Case: All child view controllers in your UITabBarController or UINavigationController do not agree on a common orientation set.

Response: To make sure that all your child view controllers rotate correctly, you must implement shouldAutorotateToInterfaceOrientation for each view controller representing each tab or navigation level. Each must agree on the same orientation for that rotate to occur. That is, they all should return YES for the same orientation positions.

http://developer.apple.com/iphone/library/qa/qa2010/qa1688.html

You may be able to set device orientation within the navigation controller instead of within individual views. Then you could check which view is on the stack and rotate based on the result. In this way, the navigation controller handles all orientation as well.

初见 2024-09-15 11:58:31

这是我用来防止该错误的一些代码:

- (void)viewDidLoad {  
    if (self.interfaceOrientation == UIInterfaceOrientationPortrait) {
        self.view.transform = CGAffineTransformIdentity;
        self.view.transform = CGAffineTransformMakeRotation(M_PI/2);
        self.view.bounds = CGRectMake(0.0, 0.0, 480, 320);
    }
    [UIView commitAnimations];
}

并且

- (void)viewDidLoad {
    if (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
        self.view.transform = CGAffineTransformIdentity;
        self.view.transform = CGAffineTransformMakeRotation(-(M_PI / 2));
        self.view.bounds = CGRectMake(0, 0, 320, 480);;
    }
    [UIView commitAnimations];
}

根据设备所在的方向,您将需要修改一些代码。

Here is some code i'm using to prevent that error:

- (void)viewDidLoad {  
    if (self.interfaceOrientation == UIInterfaceOrientationPortrait) {
        self.view.transform = CGAffineTransformIdentity;
        self.view.transform = CGAffineTransformMakeRotation(M_PI/2);
        self.view.bounds = CGRectMake(0.0, 0.0, 480, 320);
    }
    [UIView commitAnimations];
}

and

- (void)viewDidLoad {
    if (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
        self.view.transform = CGAffineTransformIdentity;
        self.view.transform = CGAffineTransformMakeRotation(-(M_PI / 2));
        self.view.bounds = CGRectMake(0, 0, 320, 480);;
    }
    [UIView commitAnimations];
}

Based on what orientation the device is in, you will need to modify some of the code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文