iPhone在应用程序启动时获取设备方向
我如何在 applicationDidFinishLaunching() 方法中获取设备方向。我尝试过UIDevice deviceorientation和StatusbarOrientaion。两者都返回不正确的值(无论当前方向如何,方向值相同)。
基本上,我试图根据设备方向加载图像,直到应用程序(webview)完成加载。所以我想我可以在这里确定当前方向并加载适当的图像(4 张图像中,每个方向一个)。
顺便说一句,我已经在 plist 文件中添加了支持的界面方向。
如果您需要任何其他信息来正确解决此问题,请告诉我 问题。
谢谢
How can i get the device orientation in applicationDidFinishLaunching() method. I have tried UIDevice deviceorientation and StatusbarOrientaion. Both returns incorrect values (same orientation value irrespective of the current orienation).
Basically, I'm trying to load an image based on the device orientation till the app(webview) completes loading. So i thought i can determine the current orientation here and load an appropriate image (out of 4 images, one for each orientation).
BTW, I have added the supported interface orientations in the plist file.
Please let me know if you require any other information for you to properly address this
question.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
之前,UIDevice 方向的值无效
在调用 beginGenerateDeviceOrientationNotifications http://developer.apple.com/library/ios/documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html#//apple_ref/occ/instm/UIDevice/beginGenerateDeviceOrientationNotifications
有你先调用这个?
The value of UIDevice orientation is invalid until you call beginGeneratingDeviceOrientationNotifications
http://developer.apple.com/library/ios/documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html#//apple_ref/occ/instm/UIDevice/beginGeneratingDeviceOrientationNotifications
Have you called this first?
我正在使用
[[UIApplication sharedApplication] statusBarOrientation]
基于这篇文章:http://www.ddeville.me/2011/01/getting-the-interface-orientation-in-ios/这就是你尝试过的说没用?我在使用
[[UIDevice currentDevice]orientation]
时遇到了麻烦,但是状态栏成功了——尽管不是在applicationDidFinishLaunching
中。我在旋转回调方法中使用它,无论如何,该方法都会在之后立即调用。 (并且回调似乎在应用程序启动时连续调用两次,第一次使用不正确的UIDeviceOrientationPortrait
,第二次使用正确的方向。)I'm using
[[UIApplication sharedApplication] statusBarOrientation]
based on this post: http://www.ddeville.me/2011/01/getting-the-interface-orientation-in-ios/Is that what you tried that you said didn't work? I had trouble with
[[UIDevice currentDevice] orientation]
, but the status bar did the trick -- though not inapplicationDidFinishLaunching
. I'm using it in the rotation callback method, which gets called immediately afterwards anyway. (And the callback appears to get called twice back-to-back at application startup, the first time with the incorrectUIDeviceOrientationPortrait
and the second time with the correct orientation.)