如何使用CGContext iOS在其他设备方向绘制string

我试图在iPhone上绘制一些文本,但是在横向模式下,主页button位于左侧。 所以我需要以某种方式扭转数字(我猜我使用了一个转换)?

这是我现在拥有的:

CGContextSetRGBFillColor(context, 1.0, 0, 0, 1.0); CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0); CGContextSelectFont(context, "Helvetica", 20, kCGEncodingMacRoman); CGContextSetTextMatrix(context, CGAffineTransformMakeRotation(M_PI/2)); CGContextSetTextDrawingMode(context, kCGTextFill); NSString *t = [NSString stringWithFormat:@"%i",seconds]; const char *str=[t UTF8String]; CGContextShowTextAtPoint(context,6.0,15.0,str,strlen(str)); 

我需要添加什么来旋转文本,以便在手机左侧的homebutton处于横向时可以阅读文本。

你必须应用两个变换matrix。 第一个将翻转文本,第二个将旋转它。 试试下面的代码:

 CGContextSetRGBFillColor(context, 1.0, 0, 0, 1.0); CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0); CGContextSelectFont(context, "Helvetica", 20, kCGEncodingMacRoman); CGAffineTransform xform = CGAffineTransformMake( 1.0, 0.0, 0.0, -1.0, 0.0, 0.0); CGContextSetTextMatrix(context, xform); CGContextConcatCTM(context, CGAffineTransformMakeRotation(M_PI_2)); CGContextSetTextDrawingMode(context, kCGTextFill); NSString *t = [NSString stringWithFormat:@"%i",seconds]; const char *str=[t UTF8String]; CGContextShowTextAtPoint(context,6.0,15.0,str,strlen(str));