Rotate around point and scale
Closed this issue · 3 comments
AlexEdunov commented
Hello. Thanks for a great work.
I'd like to implement some additional functionality. I want user to interact with view by pinch and rotate gestures. I've implemented it.
var initialQuadrilateral: AGKQuad?
@IBAction func handlePinch(_ recognizer : UIPinchGestureRecognizer) {
if (recognizer.state == .began) {
initialQuadrilateral = target.layer.quadrilateral
}
let transform = CGAffineTransform.identity.scaledBy(x: recognizer.scale, y: recognizer.scale)
target.layer.quadrilateral = AGKQuadApplyCGAffineTransform(initialQuadrilateral!, transform)
updateControlPoints()
}
@IBAction func handleRotation(_ recognizer : UIRotationGestureRecognizer) {
if (recognizer.state == .began) {
initialQuadrilateral = target.layer.quadrilateral
}
target.layer.quadrilateral = AGKQuadRotateAroundPoint(initialQuadrilateral!, target.frame, recognizer.rotation)
updateControlPoints()
}
The only problem is that view rotates and scales around zero anchor point instead of center. Could you provide an example of how to implement expected behavior.
hfossli commented
Does this happen both on pinch and rotation? or just pinch?
AlexEdunov commented
I've created an example to show what is really happening. Please take a look: https://github.com/AlexEdunov/AGGeometryKitIssue
hfossli commented
Cool. Example projects are 👌
Sent you a pull request https://github.com/AlexEdunov/AGGeometryKitIssue/pull/1
Not the prettiest code, but it seemed to work on my end.