gpt4 book ai didi

ios - Web 应用程序内存泄漏的硬件加速

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:20:24 25 4
gpt4 key购买 nike

我一直在使用 PhoneGap/Cordova 构建 Web 应用程序并且运行良好。

这些应用程序由一系列幻灯片组成,用户可以滑动以转到下一张幻灯片。我一直在使用 idangero 刷卡器来完成此操作。

一旦我尝试扩展我的应用程序以包含更多幻灯片,应用程序就会崩溃并在 XCODE 上显示内存警告。我将其缩小到 CSS3 中的硬件加速(如下)。在不崩溃的情况下,我可以拥有的 MAX 幻灯片数量是 22。添加第 23 张幻灯片后,我收到内存警告并崩溃。

我进一步缩小到

.swiper-slide {
background-color: #fff;

-webkit-transform-style: preserve-3d;
-webkit-transform: translate3d(0,0,0);
}

当我从下面的 css 中删除两个 webkit-transforms 时,应用程序编译并运行,但第一页上有白屏闪烁,像 slideToggle 这样的简单下拉动画变得不稳定。

idangero CSS

.swiper-container {
margin:0 auto;
position:relative;
overflow:hidden;
height: 768px;
width: 1024px;
z-index:1;

}

.swiper-slide {
background-color: #fff;

-webkit-transform-style: preserve-3d;
-webkit-transform: translate3d(0,0,0);
}

.swiper-wrapper {
position:absolute;
width: 100%;
-webkit-transition-property:-webkit-transform, left, top;
-webkit-transition-duration:0s;
-webkit-transition-timing-function:ease;

-moz-transition-property:-moz-transform, left, top;
-moz-transition-duration:0s;
-moz-transform:translate3d(0px,0,0);
-moz-transition-timing-function:ease;

-o-transition-property:-o-transform, left, top;
-o-transition-duration:0s;
-o-transform:translate3d(0px,0,0);
-o-transition-timing-function:ease;
-o-transform:translate(0px,0px);

-ms-transition-property:-ms-transform, left, top;
-ms-transition-duration:0s;
-ms-transform:translate3d(0px,0,0);
-ms-transition-timing-function:ease;

transition-property:transform, left, top;
transition-duration:0s;
transform:translate3d(0px,0,0);
transition-timing-function:ease;


transform: translate3d(0%,0,0) scale3d(1,1,1);
-o-transform: translate3d(0%,0,0) scale3d(1,1,1);
-ms-transform: translate3d(0%,0,0) scale3d(1,1,1);
-moz-transform: translate3d(0%,0,0) scale3d(1,1,1);
-webkit-transform: translate3d(0%,0,0) scale3d(1,1,1);
overflow: hidden;
-webkit-backface-visibility: hidden;
-webkit-transform-style: preserve-3d;


}

.swiper-free-mode > .swiper-wrapper {
-webkit-transition-timing-function: ease-out;
-moz-transition-timing-function: ease-out;
-ms-transition-timing-function: ease-out;
-o-transition-timing-function: ease-out;
transition-timing-function: ease-out;
margin: 0 auto;

}
.swiper-slide {
float: left;
}

/* IE10 Windows Phone 8 Fixes */
.swiper-wp8-horizontal {
-ms-touch-action: pan-y;
}
.swiper-wp8-vertical {
-ms-touch-action: pan-x;
}

2 个“幻灯片”的示例 html

<div class="swiper-container">
<div class="swiper-wrapper">

<!-- Home (Page 1) = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = -->
<div id="home" class="swiper-slide" rel="bkg-home.jpg">
<div class="page">
<h1>TEXt HErE</h1>
<h3>Header 3</h3>
</div><!-- /page -->
</div><!-- /home -->

<!-- Page 2 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = -->
<div id="p2" class="swiper-slide" rel="bkg-2.jpg">
<div class="page">
<div class="menu-trigger"></div>
<h1 style="padding-top:17px;">MORE TITLES</h1>
<div class="content">
<div id="table-of-contents">
<ul>
<li><a href="#p3">Issue Overview </a></li>
<li><a href="#p4">Content1</a></li>
<li><a href="#p6">Content2</a></li>
<li><a href="#p30">Content3</a></li>
<li><a href="#p17">Content4</a></li>
</ul>
</ul>
</div><!-- /table-of-contents -->

</div><!-- /content -->
<div class="header"></div><!-- /header -->
<div class="footer"></div><!-- /footer -->
<div class="footer-segment"></div><!-- /footer-segment -->
</div><!-- /page -->
</div><!-- /p2 -->
</div>
</div>

看来我需要硬件加速 CSS3 才能使应用程序平稳运行,但它似乎也会导致崩溃。有没有人有变通代码可以让我的应用程序顺利运行但不会导致整个应用程序崩溃?

最佳答案

我会尝试两种不同的方法。

1 将改变

据说硬件加速的 future 是新的 will-change css 属性。

https://dev.opera.com/articles/css-will-change-property/

.swiper-slide {
background-color: #fff;
-webkit-transform-style: preserve-3d;
/* -webkit-transform: translate3d(0,0,0); */
will-change: transform, top, left;
}

2 transforms are cheaper than positioning with top and left

我无法确定您在 topleft 上使用 transition 的确切位置,但我会尝试替换 top/left 使用 translateX()translateY()translate()

关于ios - Web 应用程序内存泄漏的硬件加速,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19163460/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com