Flutter CustomPainter画布旋转轴心 [英] Flutter CustomPainter canvas rotate pivot
本文介绍了Flutter CustomPainter画布旋转轴心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的Android Studio项目中,我按照以下步骤简单地旋转画布
In my Android Studio project, I rotate the canvas simply as following
canvas.rotate(angle, cx, cy);
使用cx和cy屏幕的中心(即枢轴).但是在Flutter中,只有一个旋转方法:
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(double radians)
正如您所看到的,当我测试它通过绘制一些矩形并旋转它而使用的轴
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);
可能我的第1行和第3行颠倒了.已修复.
这篇关于Flutter CustomPainter画布旋转轴心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文