How to use CGAffineTransformMakeRotation?

北慕城南 提交于 2019-11-26 11:01:44

问题


\"enter

I want to draw text use Quartz 2D. The \"menu\" direction is wrong. I want \"Menu\" still readable and have 45 degree with X-axis. Below is my code:

CGContextSelectFont(context, \"Arial\", 12, kCGEncodingMacRoman);
CGContextSetTextDrawingMode(context, kCGTextFill);

CGContextSetRGBFillColor(context, 0, 0, 0, 1); // 6 
CGContextSetRGBStrokeColor(context, 0, 0, 0, 1);

CGContextSetTextMatrix(context, CGAffineTransformMake(1.0,0.0, 0.0, -1.0, 0.0, 0.0));   
CGContextSetTextMatrix(context, CGAffineTransformMakeRotation(45)); 
CGContextShowTextAtPoint(context,10, 10, \"Menu\", 4);

回答1:


CGAffineTransformMakeRotation expects angle in radians, not in degrees.

#define DEGREES_TO_RADIANS(x) (M_PI * (x) / 180.0)
...

CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(45));



回答2:


[view setTransform:CGAffineTransformMakeRotation(M_PI / 2)];


来源:https://stackoverflow.com/questions/5725099/how-to-use-cgaffinetransformmakerotation

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