如何获取 iPhone 视图的当前方向或设备的最后方向?

发布于 2024-09-15 11:33:44 字数 226 浏览 11 评论 0原文

在我的应用程序中,当用户摇动设备时会出现图像。横向和纵向模式有不同的图像。如果 iPhone 的方向是纵向或横向,则效果很好。但如果是 UIDeviceOrientationFaceDownUIDeviceOrientationFaceUp,则图像应取决于上次使用的方向,因为视图仍会针​​对该方向显示。

如何获取设备的最后方向?

In my app an image appears when user shakes the device. There are different images for landscape and portrait mode. If the iPhone's orientation is portrait or landscape, it works fine. But if it is UIDeviceOrientationFaceDown or UIDeviceOrientationFaceUp, the image should depend on the last orientation used, because the view is still displayed for this orientation.

How can I get the last orientation of the device?

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

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

发布评论

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

评论(2

毅然前行 2024-09-22 11:33:45

我已经想通了!我必须检查状态栏的方向!

[UIApplication sharedApplication].statusBarOrientation

I've figured it out! I had to check the status bar's orientation!

[UIApplication sharedApplication].statusBarOrientation
只为守护你 2024-09-22 11:33:45

在类的shouldAutoRotate方法中,它传递一个名为interfaceOrientation的参数。只要设备方向发生变化,就会调用此方法。您可以将其存储为变量,并在稍后查看它以确定最后的方向。

 1 = standard portrait
 2 = upsidedown
 3 = button right landscape
 4 = button left landscape. 

此外,调用 self.interfaceOrientation 将为您提供当前的设备方向。

希望这至少能让您朝着正确的方向开始。

Well in the shouldAutoRotate method of a class it passes in a parameter called interfaceOrientation. This method is called anytime the device orientation changes. You can store this as a variable and the look at it at a later time to determine the last orientation.

 1 = standard portrait
 2 = upsidedown
 3 = button right landscape
 4 = button left landscape. 

Also the call of self.interfaceOrientation will give you the current device orientation.

Hope this at least get you started in the correct direction.

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