【问题标题】:Corona SDK system.orientation returns wrong value on iphone?Corona SDK system.orientation 在 iphone 上返回错误的值?
【发布时间】:2014-02-27 22:14:37
【问题描述】:

我注意到启动应用程序时的 system.orientation 提供了在 iphone5S 的 build.settings 中定义的默认方向。我已经在 iPad2 和 iPadMini 上测试了相同的代码并得到了正确的答案,但是对于 iphone5S,无论应用程序以哪个方向启动、任何提示或想法,我总是得到 build.settings 默认设置?

build.settings

orientation = {
    default = "portrait",
supported = {
  "landscapeLeft", "landscapeRight", "portrait", "portraitUpsideDown"
}

main.lua

print ( system.orientation ) -- gives wrong answer on iphone5S but not ipad2 or ipad Mini ?

我以打印为例,我实际上是把字符串发送到设备屏幕上。

我基本上必须旋转 5S 才能开始获取正确的方向细节,默认情况下,山雀总是说“肖像”。至少可以说在 iphone5S 上运行我的应用程序很烦人。

使用构建:版本 2013.2100 (2013.12.7)

【问题讨论】:

  • 您是否尝试过使用docs.coronalabs.com/api/event/orientation/index.html 中解释的方向监听器?不管system.orientation如何,至少你可以重建你的场景。
  • 是的,只有在 ios 7.05 上才能在 iphone5S 上得到错误结果是初始方向。如果没有称为方向的事件没有改变,我无法正确构建场景。但是 system.orientation 的结果无效,不是当前方向。
  • 啊,是的,那是不是在您的代码检查时变量尚未初始化?看看你是否可以延迟检查它,也许有一个计时器事件,也许它会在一秒钟左右后正确设置。
  • 不,太多的黑客攻击,考虑到它适用于其他基于 ios 的设备,它看起来像 7.05 或 5S 问题。
  • 我也认为这是该平台特有的问题,问题是您是否需要解决方法。计时器的想法是一个不错的 IMO,几乎不是 hack:它可以在所有平台上运行,并且不会因为升级而停止工作,如果你做得对,它可以通过注释掉一行来轻松删除代码,或者甚至可以仅用于该平台(假设 corona 具有可以查询的平台标识标签)。

标签: ios lua coronasdk


【解决方案1】:

好的,明白了。

iPad 你可以信任 system.orientation ...但 iPhone 你必须等待第一次“方向”变化发生才能信任它!假设您的代码中有一个 deviceType 类似这样的工作,

if (deviceType.isApple and not deviceType.is_iPad) then
    system.setAccelerometerInterval(100)   -- Make sure we capture first orientation change by ramping up the sample to 100Hz
    Runtime:addEventListener("orientation", initialOrientationSet) -- capture this first change
else
  -- Launch your app
end

在 initialOrientationSet 中这样做:

function initialOrientationSet ()
  Runtime:removeEventListener("orientation", initialOrientationSet)
  system.setAccelerometerInterval (10) -- save some battery power
  -- Launch you app
end

您还必须测试模拟器并正常启动它。

干杯

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-08
    • 1970-01-01
    • 2014-12-16
    • 1970-01-01
    • 2013-07-10
    • 1970-01-01
    • 2014-01-10
    相关资源
    最近更新 更多