I want to rotate a CGPoint on the screen depending on the angle and the rotation is anchored on another point. Was wondering what is the most efficient way of doing this?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- how do you prevent page scroll in textarea on mobi
- Custom UITableview cell accessibility not working
相关文章
- Could I create “Call” button in HTML 5 IPhone appl
- ceil conterpart for Math.floorDiv in Java?
- Unable to process app at this time due to a genera
- why 48 bit seed in util Random class?
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
- Open iOS 11 Files app via URL Scheme or some other
- Can keyboard of type UIKeyboardTypeNamePhonePad be
Use a CGAffineTransform.
You can also let Core Animation do it for you. Take a look at Apple's docs on layer geometry and transforms in the Core Animation Programming Guide
All you have to do is set the anchorPoint of the layer and then you can apply the transform with something like this:
DegreesToNumber converts degrees to radians and returns an NSNumber representation.
I'm not sure what you're attempting to do exactly, but often Core Animation is a great choice for visualizations.
Using Vladimir’s answer, below is the Swift 3 answer:
Use a 2D rotation matrix. If you want to rotate a point counterclockwise about the origin by an angle of
angle
, then you would do this:If you want to rotate about a point other than the origin, you'll have to first subtract the center of rotation from your point, rotate it using the above, and then add back in the center of rotation (this is called conjugation in matrix theory).
You can also use that:
EDIT: to perform rotation around custom point you must do like Adam described in his answer. Using CGAffineTransform it must look something like: