如何在 appDidBecomeActive:(UIApplication *)app 中获得正确的界面方向?
我需要在 appDidBecomeActive:(UIApplication *)application 中获取界面方向,
[application statusBarOrientation];
但如果应用程序从关闭状态启动(即不从后台恢复),则它始终返回纵向,当从后台恢复时它可以工作。
另外,我尝试将 UIDevice 方向与状态栏方向一起使用,但 UIDevice 方向可能不是界面方向。
那么有什么方法可以在应用程序委托appDidBecomeActive中获得界面方向吗?
谢谢!
I need to get interface orientation in appDidBecomeActive:(UIApplication *)application
[application statusBarOrientation];
but if the app starts from closed(ie not resumed from background), this always returns portrait, it works when resumed from background.
Also, I tried to use UIDevice orientation along with status bar orientation, but UIDevice orientation may not be the interface orientation.
So is there any way to get interface orientation in app delegate, appDidBecomeActive?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要做的是在启动视图控制器中处理这个问题。您可以使用组合interfaceOrientation、shouldAutorotateToInterfaceOrientation、didAutorotateToInterfaceOrientation 等。
本质上,创建一个将作为根视图控制器的视图控制器。在那里,确定 shouldAutorotateToInterfaceOrientation 中的方向变化(在 viewDidLoad 中它始终是纵向或横向,具体取决于您的 xib,所以不要在那里执行此操作)。用 NSTimer 或其他什么东西来显示你的图像。计时器结束后,显示您的常规应用程序屏幕。
无论如何,除非有视图控制器,否则您无法显示图像,因此您必须等到视图控制器为您提供界面方向更改。您应该关注第一个视图控制器,而不是应用程序委托。
AppDelegate.h
AppDelegate.m
What you need to do is handle this in your splash view controller. You can use a combination interfaceOrientation, shouldAutorotateToInterfaceOrientation, didAutorotateToInterfaceOrientation, etc.
Essentially, create a view controller that you will have as your root view controller. In there, determine the orientation changes in shouldAutorotateToInterfaceOrientation (it will always be portrait or landscape in viewDidLoad depending on your xib, so don't do it there). Do your image display with an NSTimer or whatever. After the timer, show your regular app screens.
You can't display the image until you have a view controller anyway, so you must wait until a view controller gives you the interfaceOrientation changes. You should focus on that first view controller, not the app delegate.
AppDelegate.h
AppDelegate.m