简体   繁体   中英

How to rotate a line on its midPoint by given angle?

I have a two CGPoints in my custom view between which i draw a line in drawRect. I have added a rotation gesture to this view in which I intend to rotate the line by the same angle over its midPoint which the recognizer gives to me.

so I change apply the transformation of that rotation both CGPoints ans then call setNeedsDisplay to get the rotated line.

I don't know what I have done wrong but my entire lines seems to be moving inside the view rather than being fixed to its centre.

Here you can find a code for making rotating with one finger. It rotates based on the center of the view for which the gesture is added. You can change the center point to make it rotate the way you like. look at below line to change.

CGPoint center = CGPointMake(CGRectGetMidX([view bounds]), CGRectGetMidY([view bounds]));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM