问题
In my Android Studio project, I rotate the canvas simply as following
canvas.rotate(angle, cx, cy);
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
and it uses top-left as pivot point. Is there a way to instruct Flutter to use my own provided pivot point?
回答1:
canvas.translate(cx, cy);
canvas.rotate(angle);
canvas.translate(-cx, -cy);
it's possible I have lines 1 and 3 reversed. Fixed.
来源:https://stackoverflow.com/questions/58042432/flutter-custompainter-canvas-rotate-pivot