ios 如何使用 CGAffineTransformMakeRotation?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5725099/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 19:38:25  来源:igfitidea点击:

How to use CGAffineTransformMakeRotation?

ioscocoa-touchcore-graphicsquartz-2d

提问by Krishnabhadra

enter image description here

在此处输入图片说明

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:

我想使用 Quartz 2D 绘制文本。“菜单”方向错误。我希望“菜单”仍然可读并且与 X 轴成 45 度。下面是我的代码:

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);

回答by Krishnabhadra

CGAffineTransformMakeRotation expects angle in radians, not in degrees.

CGAffineTransformMakeRotation 期望以弧度为单位的角度,而不是以度为单位。

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

CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(45));

回答by Sandeep Saurabh

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