本文介绍了Flutter CustomPainter画布旋转枢轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Android Studio 项目中,我简单地旋转画布,如下所示

In my Android Studio project, I rotate the canvas simply as following

canvas.rotate(angle, cx, cy);

cx 和 cy 是屏幕的中心(即枢轴).但是在 Flutter 中,只有一个 rotate 方法:

with cx and cy the center of the screen (i.e. the pivot). But in Flutter, there's only a single rotate method:

canvas.rotate(双弧度)

正如你所看到的,当我通过绘制一些矩形并旋转它来测试它使用的枢轴时

and as you can see, when I tested the pivot it uses by drawing some rectangles and rotating it

它使用左上角作为枢轴点.有没有办法指示 Flutter 使用我自己提供的枢轴点?

and it uses top-left as pivot point. Is there a way to instruct Flutter to use my own provided pivot point?

推荐答案

canvas.translate(cx, cy);
canvas.rotate(angle);
canvas.translate(-cx, -cy);

已修复.

这篇关于Flutter CustomPainter画布旋转枢轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-19 22:19