如何在启动时检测 iPad 的界面旋转?

发布于 2024-09-12 08:04:11 字数 1016 浏览 5 评论 0原文

我在让我的 iPad 应用程序在我初始化的第一个 UIViewController 中检测其 interfaceOrientation 时遇到问题(在代码中)。事实上,如果我跟踪 application.statusBarOrientation,即使我以横向启动,也会返回 1 (UIInterfaceOrientationPortrait)。

如果我在第一个 UIViewController 中跟踪 self.interfaceOrientation,它会保持为 1,直到到达 viewWillDisappear... 不幸的是为时已晚!

这是一些代码(尽管没有太多可看的):

在我的 appDelegate 中,我有这个:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    
     // show loading screen first
     [window addSubview:loadingScreenViewController.view];
     [window makeKeyAndVisible];

     NSLog(@"applicationDidBecomeActive:statusBarOrientation = %d", application.statusBarOrientation);
     return YES;
}

跟踪 1 (纵向),即使我清楚地看到状态栏是横向的......并且在第一个视图控制器中我有这个:

- (void)viewDidLoad
{
    [super viewDidLoad];
     NSLog(@"self.interfaceOrientation = %d", self.interfaceOrientation);
}

即使在横向模式下,它也会跟踪 1。

有什么想法吗?在这里难住了!

谢谢:)

:-乔

I'm having problems getting my iPad app to detect its interfaceOrientation in the first UIViewController I initialize (in code). In fact, if I trace for application.statusBarOrientation, that too returns 1 (UIInterfaceOrientationPortrait) even if I launched in landscape.

If I trace self.interfaceOrientation in my first UIViewController, it remains 1 until it gets to viewWillDisappear... Which is unfortunately too late!

Here's some code (even though there's not much to see):

In my appDelegate I have this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    
     // show loading screen first
     [window addSubview:loadingScreenViewController.view];
     [window makeKeyAndVisible];

     NSLog(@"applicationDidBecomeActive:statusBarOrientation = %d", application.statusBarOrientation);
     return YES;
}

which traces 1 (portrait), even though I clearly see the status bar is landscape... and in the first view controller I have this:

- (void)viewDidLoad
{
    [super viewDidLoad];
     NSLog(@"self.interfaceOrientation = %d", self.interfaceOrientation);
}

which also traces 1, even in landscape mode.

Any ideas? Stumped here!

Thanks :)

:-Joe

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

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

发布评论

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

评论(2

姜生凉生 2024-09-19 08:04:11

这是答案......有点:(来自苹果开发论坛):......
“应用程序总是以纵向方式加载,如果设备确实是横向方式,则应用程序会被告知设备已旋转。这样做是为了使笔尖和代码只需要在一个方向上创建其 UI。否则每个笔尖可能需要有两个 UI 布局。” .... 这不是我想要的答案,但不幸的是,这就是 iOS 的工作原理!

Here is the answer... Somewhat: (from Apple Dev Forums): ....
"The app is always loaded as if the device is portrait, and then if the device is really landscape the app is told that the device has rotated. This is done so that nibs and code only need to create their UI in one orientation. Otherwise it might be necessary to have two UI layouts for each nib." .... it's not the answer I'd have liked, but that's how iOS works unfortunately!

遮云壑 2024-09-19 08:04:11

应用程序委托在 applicationDidFinishLaunching 中报告什么?因为如果它报告正确的值,您始终可以访问委托来检查方向。

What does the app delegate report in applicationDidFinishLaunching? Because if it reports the correct value, you can always access the delegate to check the orientation.

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