简体   繁体   English

当键盘打开时,纵向模式被误解为横向

[英]Portrait mode gets misinterpreted as landscape when keyboard is on

I am developing a web application targeting tablets and mobiles.我正在开发一个针对平板电脑和手机的网络应用程序。 The system is designed to be usable, thus landscape mode as well as portrait mode must be both supported.系统设计为可用,因此必须同时支持横向模式和纵向模式。 So, when the user changes orientation my web application will fire some events to rearrange the page accordingly.因此,当用户更改方向时,我的 Web 应用程序将触发一些事件以相应地重新排列页面。

Portrait mode is misinterpreted as landscape when keyboard appears出现键盘时,纵向模式被误解为横向

Here is the problem.这是问题所在。 In all pages of my web application there is the search control consisting in a textbox and a button.在我的 Web 应用程序的所有页面中,都有一个由文本框和按钮组成的搜索控件。 When I am in portrait mode and click on the textfield, the keyboard shows and the viewport size changes having height < width which causes my application to go landscape while the device is in portrait.当我处于纵向模式并单击文本字段时,键盘显示并且视口大小更改为height < width ,这导致我的应用程序在设备处于纵向时变为横向。 When the user leaves the focus from the field, the keyboard disappears and the portrait mode is correctly recovered back.当用户离开现场焦点时,键盘消失,人像模式正确恢复。

问题说明

Take a look at the picture up here: when the user searches something, the landscape mode is activated.看看上面的图片:当用户搜索某物时,横向模式被激活。 Why?为什么? Simple: Because the viewport has changed due to the keyboard showing and the final viewport has a height lower than width.简单:因为视口因键盘显示而改变,最终视口的高度低于宽度。

在此处输入图片说明

Without the keyboard on, we have Height1 > Width1 , but when the keyboard is on we have that Height2 < Width2 but having Width2 = Width1 .没有打开键盘,我们有Height1 > Width1 ,但是当键盘打开时,我们有Height2 < Width2但有Width2 = Width1

All devices involved涉及的所有设备

As you can imagine, this is a problem actually involving all devices:可以想象,这是一个实际涉及所有设备的问题:

  • Android安卓
  • Apple iOS苹果iOS
  • Windows视窗

devices.设备。

Do you know how to fix this problem?你知道如何解决这个问题吗? What type of approaches is it possible to take to target such a scenario?针对这种情况可以采取什么类型的方法?

an Excert from https://web.archive.org/web/20160509220835/http://blog.abouthalf.com/development/orientation-media-query-challenges-in-android-browsers/来自https://web.archive.org/web/20160509220835/http://blog.abouthalf.com/development/orientation-media-query-challenges-in-android-browsers/的 Excert

To solve the twitchy keyboard problem, we need to replace blunt catch-all terms like 'portrait' with an aspect ratio that captures our weird keyboard edge case.为了解决键盘抖动的问题,我们需要用能够捕捉我们奇怪的键盘边缘情况的纵横比替换像“纵向”这样的生硬的笼统术语。

From above, we know that the screen dimensions of the Droid Razr, in portrait orientation, with the keyboard displayed, are 360px by 253px.从上面,我们知道 Droid Razr 的屏幕尺寸,纵向显示,显示键盘,为 360 像素 x 253 像素。 Divide 360 by 253 and you get 1.4 (rounded to the nearest tenth).将 360 除以 253 得到 1.4(四舍五入到最接近的十分之一)。 While we could just write an aspect ratio media query like min-aspect-ratio: 360/253, that's a little too specific to one device.虽然我们可以只编写一个纵横比媒体查询,如 min-aspect-ratio: 360/253,但这对于一个设备来说有点过于特定了。 So instead we'll use 13 to 9. That also equals roughly 1.4 but it's easier on the eyes.因此,我们将使用 13 到 9。这也大约等于 1.4,但对眼睛来说更容易一些。

For landscape media:对于横向媒体:

 @media screen and (min-aspect-ratio: 13/9) { /* landscape styles here */}

And for portrait media:对于肖像媒体:

 @media screen and (max-aspect-ratio: 13/9) { /* portrait styles here */}

It also depends how are you getting current orientation, Are you using Sensor ?它还取决于您如何获得当前方向,您是否使用 Sensor ? Result may differ from physical orientation and screen proportions结果可能与物理方向和屏幕比例不同

暂无
暂无

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

相关问题 将人像旋转到风景时,我要关闭力量,我尝试了android:configChanges =“ keyboard | keyboardHidden”并以人像模式工作吗? - Getting Force Close when rotating portrait to landscape and I tried android:configChanges=“keyboard|keyboardHidden” and working in portrait mode? 平板电脑处于横向模式时,纵向布局会消失 - portrait layout apears when the tablet is on landscape mode 纵向方向的人像键盘 - Portrait Keyboard in Landscape Orientation 在人像模式下拍摄的图像应在android中保留为横向模式 - image taken when in portrait mode should retain in landscape mode in android 握住风景时如何显示人像模式以及握住风景时如何显示风景 - How to show portrait mode when holding in landscape and landscape when holding in portrait 当设备处于横向模式时显示软键盘 - Show soft keyboard when the device is landscape mode 检测屏幕何时处于纵向或横向模式以及跨设备的屏幕边缘 - Detecting when screen is in portrait or landscape mode and the edges of a screen across device 以人像然后以横向模式连续拍照时,应用程序崩溃 - Application crashes when taking photos successively in portrait then in landscape mode 将布局从纵向模式切换为横向模式时出现问题 - Problem when switching layouts from portrait to landscape mode 当方向从纵向更改为横向模式时出现意外行为 - unexpected behaviour when orientation changes from portrait to landscape mode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM