简体   繁体   English

停止iOS7放大WebView

[英]Stop iOS7 zoom in webview

I have looked at other questions similar to this and they do not ask the exact question that I need to ask! 我看过其他与此类似的问题,但它们并没有提出我需要提出的确切问题!

Question: How do I stop WebView from zooming in on an input field AND still respond to css media queries. 问题:如何停止WebView放大输入字段,并且仍然响应CSS媒体查询。

The reason for the last part is this: 最后一部分的原因是:

<meta name="viewport" content="user-scalable=1.0,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,width=device-width, height=device-height">

When I use this meta tag, notice the width=device-width and height=device-height . 当我使用此元标记时,请注意width=device-widthheight=device-height This is good because it stops the zooming on the WebView on my iPad. 这很好,因为它停止了iPad上WebView的缩放。

However, with this, my css queries stop working! 但是,与此同时,我的CSS查询停止工作! My css is: 我的CSS是:

@media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait) {
  /* For portrait layouts */
  #wrap{width:768px;height:1024px;background-color:#FFF;border:1px solid gray;position:relative;}
  form{width:380px;overflow:hidden;padding-top:30px; padding-left: 40px;}
  .results{position:absolute;top:0;right:0;left:0;bottom:0;background-color:#FFF;height:100%;float:right;color:#000;display:none;}
}

@media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape) {
  /* For landscape layouts */
  #wrap{width:1024px !important;height:768px;background-color:#FFF;border:1px solid gray;position:relative;margin:0 auto;}
  form{width:511px;overflow:hidden;padding-top:30px; padding-left: 106px;}

}

As you can see, the top query is portrait and the bottom landscape. 如您所见,最上面的查询是纵向,最下面的查询是横向。 When I have the meta tag in, it will only load the portrait version (no matter how what orientation the iPad). 当我插入meta标签时,它将仅加载纵向版本(无论iPad的方向如何)。 This is because the meta tag is setting the height and width. 这是因为meta标签正在设置高度和宽度。

If I take away the width=device-width and height=device-height in the meta tag, then the css works again, but then the zooming in on inputs when focus also does. 如果我删除meta标签中的width=device-widthheight=device-height ,那么css将再次起作用,但是当焦点也起作用时,放大输入。

I had tried some JavaScript fixes but I actually got a better result with the zooming using the simple meta tag, but I am open to a JavaScript fix also. 我已经尝试了一些JavaScript修复程序,但是使用简单的meta标签进行缩放实际上可以获得更好的结果,但是我也可以使用JavaScript修复程序。

<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, minimal-ui">

Plus, why are you adding such constrained widths on your elements? 另外,为什么要在元素上添加这样的约束宽度? By that point, you should maybe look in to responsive design . 到那时,您也许应该研究响应式设计

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

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