uniapp map组件ios端circles.fillColor无效

在这里插入图片描述
fillColor文档说明:8位十六进制表示,后两位表示alpha值,如:#0000AA。Android可以,IOS无效。
应改为:rgba,如:rgba(0,0,0,0.2)

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这里提供一种思路,可以使用canvas绘制6个不规则运动的圆: 1. 在uniapp页面添加canvas组件: ``` <canvas canvas-id="myCanvas" style="width: 100%; height: 100vh"></canvas> ``` 2. 在页面的onLoad生命周期函数获取canvas上下文: ``` onLoad() { const ctx = uni.createCanvasContext('myCanvas', this) this.ctx = ctx }, ``` 3. 定义6个不规则运动的圆的初始位置和速度: ``` data() { return { circles: [ { x: 50, y: 50, vx: 2, vy: 1 }, { x: 100, y: 100, vx: -1, vy: 2 }, { x: 150, y: 150, vx: 1, vy: -2 }, { x: 200, y: 200, vx: -2, vy: -1 }, { x: 250, y: 250, vx: 2, vy: -1 }, { x: 300, y: 300, vx: -1, vy: -2 }, ] } }, ``` 4. 在canvas的绘制函数循环绘制每个圆: ``` draw() { const { circles } = this const ctx = this.ctx for (let i = 0; i < circles.length; i++) { const { x, y } = circles[i] ctx.beginPath() // 绘制不规则圆 ctx.arc(x, y, 20, 0, 2 * Math.PI) ctx.fillStyle = '#f00' ctx.fill() // 更新圆的位置 circles[i].x += circles[i].vx circles[i].y += circles[i].vy } ctx.draw() // 每隔一段间重新执行绘制函数 setTimeout(this.draw, 30) }, ``` 5. 在页面的onReady生命周期函数调用绘制函数: ``` onReady() { this.draw() }, ``` 完整代码如下: ``` <template> <canvas canvas-id="myCanvas" style="width: 100%; height: 100vh"></canvas> </template> <script> export default { data() { return { circles: [ { x: 50, y: 50, vx: 2, vy: 1 }, { x: 100, y: 100, vx: -1, vy: 2 }, { x: 150, y: 150, vx: 1, vy: -2 }, { x: 200, y: 200, vx: -2, vy: -1 }, { x: 250, y: 250, vx: 2, vy: -1 }, { x: 300, y: 300, vx: -1, vy: -2 }, ] } }, onLoad() { const ctx = uni.createCanvasContext('myCanvas', this) this.ctx = ctx }, onReady() { this.draw() }, methods: { draw() { const { circles } = this const ctx = this.ctx for (let i = 0; i < circles.length; i++) { const { x, y } = circles[i] ctx.beginPath() // 绘制不规则圆 ctx.arc(x, y, 20, 0, 2 * Math.PI) ctx.fillStyle = '#f00' ctx.fill() // 更新圆的位置 circles[i].x += circles[i].vx circles[i].y += circles[i].vy } ctx.draw() // 每隔一段间重新执行绘制函数 setTimeout(this.draw, 30) } } } </script> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值