CGContext rotation

♀尐吖头ヾ 提交于 2019-12-03 03:27:58

Rotation is always about the origin; what you need to do is not to defeat that, but to take advantage of it.

The key thing to remember here is that translation moves the origin. So, if you want to have the image centered at the center of the screen and rotate the image around that center, what you need to do is:

  1. Move the origin to the center of the screen.
  2. Rotate by the desired amount. (Imagine the extreme ends of the x axis moving as you do this; the left end tilts down, and the right end tilts up.)
  3. Move the origin “left” and “down” (both of these being along the new x and y axes) by half the size of the image.

Imagine the motion of the image on the iPad through each of these steps. Or, better yet, take a Post-It note and simulate it by hand:

  1. Start out with the note in a corner of the iPad.
  2. Move the note so that that corner of the note is in the center of the iPad.
  3. Rotate the note around that corner.
  4. Move the note “left” (relative to itself) by half its width and “down” (relative to itself) by half its height.

You'll notice that the note ends up rotated and in the center.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!