UIView transformation to SVG matrix
I am currently embedding an image into an exported SVG document and am running into an issue with the transformation matrix on a UIView that I am scaling and moving. My output currently pushes the matrix into the attribu开发者_如何学编程te transform
transform="matrix(view.transform.a, view.transform.b, view.transform.c, view.transform.d, view.transform.tx, view.transform.ty)"
This all works perfectly fine with the exception of the tx and ty values of the transformation. For some reason when I scale the view these values start getting weird , and I'm not sure what is going on. Obviously core graphics is handeling the matrix a little different than svg is, but does anyone know what the difference is?
It looks like CoreGraphics sets up the transform so that the vector is in the center of the view while in SVG the vector would be at top left of the image.
Multiplying the transform solved this for me:
// create an offset matrix<br />
CGAffineTransform offset1 = CGAffineTransformMake(1, 0, 0, 1, -originalViewWidth/2, -originalViewHeight/2);
CGAffineTransform offset2 = CGAffineTransformMake(1, 0, 0, 1, originalViewWidth/2, originalViewHeight/2);
CGAffineTransform matrix = CGAffineTransformConcat(offset1, view.transform);
matrix = CGAffineTransformConcat(matrix, offset2);
精彩评论