简体   繁体   English

PhoneGap应用中的Windows Phone屏幕高度不是100%

[英]Windows Phone screen height in PhoneGap app not 100%

I'm developing a Windows Phone app using PhoneGap/Cordova (though, I believe the problem I'm having makes the fact that it's PhoneGap irrelevant). 我正在使用PhoneGap / Cordova开发一个Windows Phone应用程序(不过,我相信我遇到的问题使得它与PhoneGap无关)。 No matter what I seem to do, the tag of my html pages doesn't fill the screen vertically. 无论我做什么,我的html页面的标签都不会垂直填满屏幕。 It looks fine when running the pages in Chrome or even IE Here is what it looks like on the Emulator, I added a blue border to the tag in the .css for emphasis of what's going on: 在Chrome或甚至IE中运行页面时看起来很好。这就是模拟器上的样子,我在.css中为标签添加了一个蓝色边框,以强调正在发生的事情:

在此输入图像描述

Here's the css for the body: 这是身体的css:

  body{
    border: 1px blue solid;

}

html, body{
    height:100%;
    min-height:100%
}

here's the footers css: 这是页脚css:

div.navbar_table_container {
    width: 100%;
    height: auto;   
    position: absolute;
    bottom: 0;
    background-image:url(images/bottom-nav.png);
    background-size:100% 100%;
    background-repeat:no-repeat;
    text-align: center;
}

and, as it may be important, here's the xaml file: 并且,因为它可能很重要,这是xaml文件:

<phone:PhoneApplicationPage 
    x:Class="CordovaWP8_2_7_01.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    Background="White"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True" d:DesignHeight="820" d:DesignWidth="480" 
    xmlns:my="clr-namespace:WPCordovaClassLib">
    <Grid x:Name="LayoutRoot" Background="Transparent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <my:CordovaView HorizontalAlignment="Stretch" 
                   Margin="0,0,0,0"  
                   x:Name="CordovaView" 
                   VerticalAlignment="Stretch" />
        <Image Source="SplashScreenImage.jpg"
          x:Name="SplashImage"
          VerticalAlignment="Stretch"
          HorizontalAlignment="Stretch">
            <Image.Projection>
                <PlaneProjection x:Name="SplashProjector"  CenterOfRotationX="0"/>
            </Image.Projection>
        </Image>
    </Grid>

</phone:PhoneApplicationPage>

an important note is that it works the way I want it to in Chrome, IE, and when I run it as an android app. 一个重要的注意事项是它在Chrome,IE以及我作为Android应用程序运行时的工作方式。

The closest question to mine that I could find was Phonegap Windows Phone gap space bottom but the answer there doesn't help me. 我能找到的最接近我的问题是Phonegap Windows Phone缺口空间底部,但答案对我没有帮助。

I've noticed recently that when I run the same code off of a web server and access it using IE on a windows phone, it looks fine. 我最近注意到,当我从Web服务器上运行相同的代码并使用Windows上的IE访问它时,它看起来很好。 However, I did notice that whenever an Alert was shows on the phone, the address bar of IE goes away and leaves behind the EXACT same gap from the bottom of the web content to the bottom of the phone as the native app is always showing. 但是,我确实注意到,每当手机上显示警报时,IE的地址栏就会消失,并留下从网络内容底部到手机底部的完全相同的差距,因为本机应用程序始终显示。

So, that leads me to believe that, even though it's an "app", if it's running html and javascript, the phone leaves space for an address bar, even though it's never used. 因此,这让我相信,即使它是一个“应用程序”,如果它运行html和javascript,手机会留出一个地址栏空间,即使它从未使用过。

Any help or insight would be greatly appreciated. 任何帮助或见解将不胜感激。

I tried using device-height in the viewport meta tag, however I learned that IE doesn't support that tag. 我尝试在viewport元标记中使用device-height,但是我了解到IE不支持该标记。 Then after my 100,000 google search, I found this page . 在我的100,000搜索之后,我找到了这个页面

After adding this to my CSS: 将此添加到我的CSS后:

@viewport{height:device-height}
@viewport{width:device-width}
@-ms-viewport{height:device-height}
@-ms-viewport{width:device-width}

and adding this to a JavaScript file that hits all of my pages: 并将其添加到一个能够访问我所有页面的JavaScript文件中:

if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
    var msViewportStyle = document.createElement("style");

    msViewportStyle.appendChild(
        document.createTextNode(
            "@-ms-viewport{width:auto!important}"
        )
    );

    msViewportStyle.appendChild(
        document.createTextNode(
            "@-ms-viewport{height:device-height!important}"
        )
    );

    document.getElementsByTagName("head")[0].appendChild(msViewportStyle);
}

Then my 100% body height started acting the way that I would expect it to. 然后我的100%身高开始按照我期望的方式行事。

In your MainPage.xaml file, change MainPage.xaml文件中,进行更改

shell:SystemTray.IsVisible="True"

to

shell:SystemTray.IsVisible="False"

it seems that the key is width property in -ms-viewport, so a simpler solution would be: 似乎关键是-ms-viewport中的width属性,因此更简单的解决方案是:

// put this in body or after body as it uses document.body.offsetWidth.
if (/IEMobile\/10\.0/.test(navigator.userAgent)) {
    document.write('<style>@-ms-viewport { width: ' + document.body.offsetWidth + 'px; }</style>');
}

The overflow is a weird IE10 WebBrowser control thing. 溢出是一个奇怪的IE10 WebBrowser控件。 If you change the background color of the body you will see that both above and below your div are the background color. 如果更改正文的背景颜色,您将看到div的上方和下方都是背景颜色。

Here is a simple workaround: 这是一个简单的解决方法:

document.addEventListener("DOMContentLoaded", function () {
    var div = document.querySelector(".navbar_table_container");
    div.style.top = (div.offsetTop + div.offsetHeight + 4) + "px";
});

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

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