【问题标题】:Fonts are Loading Randomly on Cordova App for iOS字体在 iOS 的 Cordova 应用程序上随机加载
【发布时间】:2019-05-03 13:09:40
【问题描述】:

我们有一个 Cordova 网络应用程序(HTMLJSCSS),由于某些原因,在 iPhone XS 和 XR 等高端设备上,有时无法加载字体。

我启动应用程序并没有加载字体,我最小化应用程序再次返回字体正常。

有时我打开应用程序,一切都很好!在 iPhone、8、7、6 和 SE 上,我们根本没有遇到这个错误。这完全是随机的。

我改变了导入 SaSS 文件的顺序,同样的事情发生了

这是我们如何通过 SaSS 称呼喜欢的人:

    @include font-face("dosisbold", "../fonts/dosis/dosis-bold-webfont", $__file-formats: woff2 woff ttf);
    @include font-face("dosissemibold", "../fonts/dosis/dosis-semibold-webfont", $__file-formats: woff2 woff ttf);
    @include font-face("dosisextrabold", "../fonts/dosis/dosis-extrabold-webfont", $__file-formats: woff2 woff ttf);

@mixin font-face( $__font-family, $__file-path, $__weight: normal, $__style: normal, $__file-formats: eot woff2 woff ttf svg ) {

    // Possible font formats
    $formats: (
        eot   : "#{$__file-path}.eot?#iefix" format("embedded-opentype"),
        woff2 : "#{$__file-path}.woff2" format("woff2"),
        woff  : "#{$__file-path}.woff" format("woff"),
        ttf   : "#{$__file-path}.ttf" format("truetype"),
        svg   : "#{$__file-path}.svg##{$__font-family}" format("svg")
    );


    // Creates the font sources
    $fonts-src: ();
    @each $formats_key, $formats_values in $formats {
        @if index($__file-formats, $formats_key) != null {
            $fonts-src: append($fonts-src, url(nth($formats_values, 1)) nth($formats_values, 2), comma);
        }
    }


    // Outputs the @font-face rule
    @font-face { font-family: $__font-family; font-weight: $__weight; font-style: $__style; src: $fonts-src; }
}

【问题讨论】:

  • 尝试以下解决方案:stackoverflow.com/questions/43269174/…
  • 这正是我们所做的......它似乎与我发布的代码不同,但它是一个 mixin。
  • 这意味着您正在创建字体混合,您应该将其内容分享到问题中以希望得到答案。
  • 我的错!我编辑我的问题!

标签: javascript ios cordova


【解决方案1】:

我猜你的混音可能是这样的:

@mixin font-face($style-name, $filepath, $category:"") {

    @font-face {
        font-family: "#{$style-name}";
        src: url($filepath + ".woff2") format('woff2'), url($filepath + ".woff") format('woff'), url($filepath + ".ttf")  format('truetype'), ;
    }

    %#{$style-name} {
        font: {
            @if $category == "" {
              family: "#{$style-name}";
              weight: normal;
            }
            @else {
              family: "#{$style-name}", #{$category};
            }
        }
    }
}

$family: 'dosis';
$file: 'dosis-bold-webfont';
$filepath: "fonts/" + $family + "/" + $file;
@include font-face('dosis', $filepath , 'serif');

这将产生:

@font-face {
  font-family: "dosis";
  src: url("fonts/dosis/dosis-bold-webfont.woff2") format("woff2"), url("fonts/dosis/dosis-bold-webfont.woff") format("woff"), url("fonts/dosis/dosis-bold-webfont.ttf") format("truetype");
}

这是您要搜索的内容吗?

【讨论】:

  • 主要问题是iOS上的字体随机加载!启动 10 次应用程序 8 次字体加载完美,2 次没有字体!所以我想我的 mixins 很好,因为一切都很好!但我会试一试你的代码!
  • 同样的事情发生了! :(
  • 嗯。做下面的实验。只需将这部分设为纯 CSS 并像刚才一样对其进行测试。让我们先排除它来确认问题与 SaSS 代码有关。
猜你喜欢
  • 1970-01-01
  • 2018-12-20
  • 2016-10-25
  • 1970-01-01
  • 1970-01-01
  • 2012-12-07
  • 2021-07-13
  • 1970-01-01
  • 2017-11-13
相关资源
最近更新 更多