唏嘘的胡渣
唏嘘的胡渣
  • 发布:2020-01-21 11:21
  • 更新:2023-04-25 17:24
  • 阅读:2012

【报Bug】canvas 在app上清除重绘会出现明显的闪烁

分类:uni-app

详细问题描述

(DCloud产品不会有明显的bug,所以你遇到的问题大都是在特定环境下才能重现的问题,请仔细描述你的环境和重现方式,否则DCloud很难排查解决你的问题)

[内容]

首先我绘制一端文字,然后手势滑动对应位置出现一个长宽均为10px的正方形
每次滑动都会清除画布重绘文字和正方形。

[结果]

每次滑动正方形会有明显的闪烁。

[期望]

每次滑动正方形不会有明显的闪烁。

IDE运行环境说明

HBuilderX

[IDE版本号]

2.5.1.20200103

[windows版本号]

[mac版本号]

uni-app运行环境说明

app

项目是HBuilderX创建的

老模板模式

App运行环境说明

[Android版本号]

Android 9

[iOS版本号]

[手机型号]

Redmi Note8

[模拟器型号]

附件

[可重现代码片段]

<template>  
    <view >  
        <canvas canvas-id="canvas"  
         @touchmove="touchmove"  
         @touchstart="touchmove"  
         @touchend="touchmove"  
         style="width: 750rpx;height: 500rpx;"></canvas>  
    </view>  
</template>  

<script>  
    export default {  
        data() {  
            return {  
                title: 'Hello'  
            }  
        },  
        onLoad() {  
            this.width = uni.upx2px(750);  
            this.height = uni.upx2px(500);  
        },  
        onReady() {  
            this.context = uni.createCanvasContext('canvas',this);  
            this.drawTxt()  
        },  
        methods: {  
            touchmove(e){  
                this.context.clearRect(0,0,this.width,this.height)  
                this.drawTxt()  
                this.context.font = '20px STheiti, SimHei';  
                this.context.textAlign = 'center';  
                this.context.fillRect(e.touches[0].x, e.touches[0].y,10,10);  
                this.draw();  
            },  
            draw(){  
                // #ifdef H5  
                setTimeout(() => {  
                    this.context.draw(true)  
                },200)  
                // #endif  
                // #ifndef H5  
                this.context.draw(true)  
                // #endif  
            },  
            drawTxt(){  
                this.context.font = '20px STheiti, SimHei';  
                this.context.fillText('Canvas API中文网', 24, 66);  
                this.context.fillText('Canvas API中文网', 24, 80);  
                this.context.fillText('Canvas API中文网', 24, 100);  
                this.draw();  
            }  
        }  
    }  
</script>  

<style>  

</style>

联系方式

[QQ]

624428121

2020-01-21 11:21 负责人:无 分享
已邀请:
u***@126.com

u***@126.com - 青岛普联

我也遇到同样问题,这个应该如何解决呢?

道道123

道道123

同遇

唏嘘的胡渣

唏嘘的胡渣 (作者) - 懒贯穿了整个人生,咸鱼就是一生的梦想

出现该问题的原因是重复调用了draw(),只需要在最后一下调用draw()即可

  • 道道123

    好的,感谢,我试试

    2020-10-10 15:21

1***@qq.com

1***@qq.com

解决了嘛?我也想知道解决方法

要回复问题请先登录注册