简体   繁体   English

iPhone在应用启动时获取设备方向

[英]iphone get device orientation on app launch

How can i get the device orientation in applicationDidFinishLaunching() method. 如何在applicationDidFinishLaunching()方法中获取设备方向。 I have tried UIDevice deviceorientation and StatusbarOrientaion . 我已经尝试过UIDevice deviceorientationStatusbarOrientaion 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. 基本上,我试图基于设备方向加载图像,直到app(webview)完成加载。 So i thought i can determine the current orientation here and load an appropriate image (out of 4 images, one for each orientation). 所以我想我可以在这里确定当前方向并加载适当的图像(4张图像中的每个方向一个)。

BTW, I have added the supported interface orientations in the plist file. 顺便说一句,我已经在plist文件中添加了受支持的界面方向。

Please let me know if you require any other information for you to properly address this question. 如果您需要其他任何信息以正确解决此问题,请告诉我。

Thanks 谢谢

The value of UIDevice orientation is invalid until you call beginGeneratingDeviceOrientationNotifications 在您调用beginGeneratingDeviceOrientationNotifications之前,UIDevice orientation的值是无效的

http://developer.apple.com/library/ios/documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html#//apple_ref/occ/instm/UIDevice/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? 你先打过电话吗

I'm using [[UIApplication sharedApplication] statusBarOrientation] based on this post: http://www.ddeville.me/2011/01/getting-the-interface-orientation-in-ios/ 我正在根据此信息使用[[UIApplication sharedApplication] statusBarOrientation]http : [[UIApplication sharedApplication] statusBarOrientation]

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 in applicationDidFinishLaunching . 我在[[UIDevice currentDevice] orientation]遇到了麻烦,但是状态栏可以解决问题-尽管不是在applicationDidFinishLaunching 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 incorrect UIDeviceOrientationPortrait and the second time with the correct orientation.) (并且回调似乎在应用程序启动时被背对背调用了两次,第一次是使用错误的UIDeviceOrientationPortrait ,第二次是使用了正确的方向。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM