一个CSS样式引发的APP崩溃卡顿-webkit-overflow-scrolling:touch

本文探讨了在iOS应用中使用-webkit-overflow-scrolling:touch样式以提高滑动流畅性的方法,并分析了该样式导致iPhone 6及以上设备崩溃的原因。推测此问题源于样式启用GPU加速从而增加APP运行内存。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

为了让iOS系统下用默认的滑动更加流畅,给滚动区域添加了如下样式:

-webkit-overflow-scrolling:touch

引起APP在iphone 6以上机型的崩溃率升高。经排查验证,去掉这个样式后就恢复正常了。

 

原因推测:因为这个样式会开启GPU加速,导致APP 运行内存过高而引起的崩溃。

 

先记录一下。

转载于:https://www.cnblogs.com/mjian/p/9250058.html

<template> <view class="tui-notice-vertical" :style="{width:width?width+'rpx':'100%',height:scrollHeight+'px',background:background,padding:padding,borderRadius:radius+'rpx'}"> <view :id="elId_box" class="tui-seamless__scroll-outer"> <view :id="elId" class="tui-seamless__scroll-box" :style="{paddingTop:scrollHeight+'px', 'animationDuration': animationDuration,'-webkit-animationDuration': animationDuration,animationPlayState: webviewHide?'paused':animationPlayState,'-webkit-animationPlayState':webviewHide?'paused':animationPlayState, animationDelay: animationDelay, '-webkit-animationDelay':animationDelay}"> <slot></slot> </view> </view> </view> </template> <script> export default { name: "tui-notice-vertical", props: { //滚动容器宽度 rpx ,0 则使用屏幕宽度 width: { type: [Number, String], default: 0 }, //滚动容器高度 rpx height: { type: [Number, String], default: 400 }, background: { type: String, default: 'transparent' }, radius: { type: [Number, String], default: 0 }, padding: { type: String, default: '0' }, //每秒滚动速度(距离) 默认 20px/s speed: { type: [Number, String], default: 20 }, //backwards: 动画从头开始播;forwards:动画从结束点开始播 activeMode: { type: String, default: 'backwards' } }, watch: { height(val) { this.scrollHeight = uni.upx2px(Number(val) || 600) } }, data() { const elId = `tui_${Math.ceil(Math.random() * 10e5).toString(36)}` const elId_box = `tui_${Math.ceil(Math.random() * 10e5).toString(36)}` return { elId, elId_box, webviewHide: false, boxHeight: 0, contentHeight: 0, scrollHeight: 0, animationDuration: 'none', animationPlayState: 'paused', animationDelay: '0s' }; }, created() { this.scrollHeight = uni.upx2px(Number(this.height) || 600) }, mounted() { // #ifdef APP-PLUS let pages = getCurrentPages(); let page = pages[pages.length - 1]; let currentWebview = page.$getAppWebview(); currentWebview.addEventListener('hide', () => { this.webviewHide = true }) currentWebview.addEventListener('show', () => { this.webviewHide = false }) // #endif this.$nextTick(() => { setTimeout(() => { this.initAnimation() }, 50) }) }, methods: { initAnimation() { let query = [], boxHeight = 0, contentHeight = 0; let noticeQuery = new Promise((resolve, reject) => { uni.createSelectorQuery() // #ifndef MP-ALIPAY .in(this) // #endif .select(`#${this.elId}`) .boundingClientRect() .exec(ret => { this.contentHeight = ret[0].height resolve() }) }) if (this.activeMode === 'forwards') { let boxQuery = new Promise((resolve, reject) => { uni.createSelectorQuery() // #ifndef MP-ALIPAY .in(this) // #endif .select(`#${this.elId_box}`) .boundingClientRect() .exec(ret => { this.boxHeight = ret[0].height resolve() }) }) query.push(boxQuery) } query.push(noticeQuery) Promise.all(query).then(() => { this.animationDuration = `${this.contentHeight /(Number(this.speed) || 20)}s` if (this.activeMode === 'forwards') { this.animationDelay = `-${this.boxHeight / (Number(this.speed) || 20)}s` } setTimeout(() => { this.animationPlayState = 'running' }, 1000) }) } } } </script> <style scoped> .tui-notice-vertical { width: 100%; position: relative; box-sizing: border-box; overflow: hidden; display: flex; flex-direction: column; z-index: 2; } .tui-seamless__scroll-outer { width: 100%; flex: 1; overflow: hidden; } .tui-seamless__scroll-box { width: 100%; position: absolute; left: 0; top: 0; word-break: break-all; white-space: pre-wrap; animation: notice 10s 0s linear infinite both; animation-play-state: paused; -webkit-backface-visibility: hidden; -webkit-perspective: 1000; } @keyframes notice { 100% { transform: translate3d(0, -100%, 0); } } </style>这段代码是uniapp一个滚动组件,如何让这个组件滚动的起始位置在顶部,从顶部开始滚动
06-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值