简体   繁体   English

iPad上的iOS UIWebView窗口宽度和高度

[英]iOS UIWebView window width and height on iPad

So I'm creating a full screen ad that runs inside a UIWebView in an unnamed app. 因此,我正在创建一个全屏广告,该广告将在未命名的应用程序的UIWebView中运行。 Basically, I can't modify the viewport metatag at all, so my app needs to be exact 1023x767 to be full screen and wont scroll around the webview. 基本上,我根本无法修改视口元标记,因此我的应用必须准确地为1023x767才能全屏显示,并且不会在Webview上滚动。 It works 95% of the time, except one scenario that triggers a weird bug. 它能在95%的时间内工作,除了一种情况会触发怪异的错误。 If I start in landscape, then rotate to horizontal, I'm able to scroll the app around the webview as if it is larger than the viewport. 如果我从横向开始,然后旋转到水平,则可以在Web视图周围滚动应用程序,就好像它大于视口一样。

In the CSS, I have: 在CSS中,我有:

@media only screen and (orientation: portrait) {
    html, body {
        width: 767px;
        height: 1023px;
        overflow:hidden;
        position:relative;
    }
}

@media only screen and (orientation:landscape) {
    html, body {
        width: 1023px;
        height: 767px;
        overflow:hidden;
        position:relative;
    }
}

I am detecting events on orientation change, and I'm getting: 我正在检测有关方向改变的事件,并且得到:

$('html').width() = 767
$('html').height() = 1023
$('body').width() = 767
$('body').height() = 1023

However, I found out I'm also getting this at the same time, which is obviously the problem, but I can't figure out why or how to fix it: 但是,我发现我也同时得到了这个,这显然是问题所在,但是我不知道为什么或如何解决它:

$(window).width() = 1023
$(window).height() = 1365

Any thoughts? 有什么想法吗? Anyone!? 任何人!? :-) :-)

So, through more research, the reason I wasn't able to use the veiwport metatag to establish width=device-width is because the viewport is actually set 1px smaller than the device width. 因此,通过更多的研究,我之所以无法使用veiwport元标记来建立width = device-width的原因是,视口实际上设置为比设备宽度小1px。 Then, you'd have scrolling in the viewport in that dead pixel area. 然后,您需要在该盲像素区域的视口中滚动。 The app detects left and right swipes to change between different webviews, so you can't perform a "e.preventDefault()" to disable scrolling, and having it stuck in that 1px of scrolling screws up the swiping functionality in the app. 该应用程序检测到左右滑动以在不同的Web视图之间切换,因此您无法执行“ e.preventDefault()”来禁用滚动,而将其卡在滚动的1像素中会破坏应用程序中的滑动功能。

Long story short, I was able to do: 长话短说,我能够做到:

viewport=(device-width-1) and it fixed the issue. viewport =(device-width-1),它解决了此问题。 The app people didn't know this was possible, and I wasn't even sure something like this was possible, but it made it so the swiping could still occur because you weren't getting stuck in that deadspace. 该应用程序的人们并不知道这是可能的,而且我什至不确定这种事情是否可行,但是它成功了,所以仍然可以进行刷卡操作,因为您不会陷入死角。

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

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