iOS 模拟器在方向检测方面有问题吗?
我正在从苹果(xcode)获得的ios模拟器上测试一段代码。 基本上我试图在用户旋转 ipad 时重置缩放比例,但在模拟器上它非常不一致。我最初的基本代码是说如果方向是 90 则执行此操作,如果方向是 -90 则执行此操作,依此类推,但如果我的原始方向是横向或纵向,则可能会搞砸。这种行为仅适用于ios模拟器还是与ipad相同,我没有ipad,所以我无法验证
何时重置缩放,我首先将元标记内容全部删除,然后再次添加到内容,因为如果我不这样做这样做,它根本不起作用
示例代码是,我尝试使用设备宽度,它只是搞砸了。我不想使用CSS,因为内容是固定宽度的,所以我只需要重新缩放。难道我的方法错了?还有另一种经过测试的方法吗?我以前使用过 switch 语句,但我发现 if 更简单。谢谢
if (orientation == 0 || orientation == 180) {
viewport.attr("content", "");
viewport.attr("content", "user-scalable=no, initial-scale=1, minimum-scale=1, maximum-scale=1, width=990px");
}
else {
viewport.attr("content", "");
viewport.attr("content", "user-scalable=no, initial-scale=0.77, minimum-scale=0.77, maximum-scale=0.77, width=990px");
}
}
I am testing a piece of code on the ios simulator you get from apple (xcode).
basically I am trying to reset the scaling when the user rotates the ipad but on the simulator it is so inconsistant. I originally had the basic code to say if orientation is 90 do this, if it is -90 do that and so on but if my original orientation is landscape or portrait it might screw up. is this behavior just with ios simulator or the same as ipad, i don't have an ipad with me so i cannot verify
when i reset the scaling i am first removing the meta tag content all together then adding to content again because if i dont do so, it does not work at all
sample code would be, i have tried using device width, it just screws up. I dont want to use css because the content is fix width so i just need to rescale. is my method wrong? is there another tested approach? I used a switch statement before but i find the if much simpler. thank you
if (orientation == 0 || orientation == 180) {
viewport.attr("content", "");
viewport.attr("content", "user-scalable=no, initial-scale=1, minimum-scale=1, maximum-scale=1, width=990px");
}
else {
viewport.attr("content", "");
viewport.attr("content", "user-scalable=no, initial-scale=0.77, minimum-scale=0.77, maximum-scale=0.77, width=990px");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
XCode 模拟器非常好,我从来没有遇到过任何问题,除了它有时对方向变化的反应有点慢。
如果您想使用 JavaScript 检查它,我认为您最好尝试将 window.innerHeight 与 window.innerWidth 进行比较,看看哪一个最大。
我不久前制作了一个测试页面,它仅使用 CSS 来测试某些媒体查询内容。
链接:http://pm5544.eu/mp/
请注意,在横向时,设备的宽度和高度不会改变,这(至少对我来说)有点违反直觉,因此 iOS 设备有时可能会提供意外的信息。
我可以问一下为什么你不想使用 CSS 来实现这一点,因为听起来这是非常可行的。
PM5544。
The XCode simulator is pretty good and i never had problems with it besides it sometimes react a bit slow to orientation changes.
If you would want to check it with JavaScript i think you would best try comparing the window.innerHeight to the window.innerWidth and see which one is largest.
I made a test page a while back which uses only CSS to test for certain media query things.
link: http://pm5544.eu/mp/
Notice that when in landscape orientation the device width and height do not change, this was (at least to me) a bit counter-intuitive, so it might be that the iOS devices give unexpected info sometimes.
May i ask why you don't want to use CSS for this because it sounds like it is very doable.
PM5544.
我不能 100% 确定方向是否需要为度数,
-90, 90
。如果没有,那么你可以尝试使用..orientation == Landscape
这是一个有效的 CSS3 媒体查询
http://www.1stwebdesigner.com/css/如何使用-css3-orientation-media-queries/
I'm not 100% sure if the orientation needs to be a degree,
-90, 90
. If it doesn't then you could try using..orientation == landscape
It's a valid CSS3 media query
http://www.1stwebdesigner.com/css/how-to-use-css3-orientation-media-queries/