如何在iPhone上旋转Quartz绘制的文本 [英] How to rotate text drawn by Quartz on iPhone

查看:132
本文介绍了如何在iPhone上旋转Quartz绘制的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Quartz绘制一些文本。现在,该应用程序将获得
alt text http://www.freeimagehosting.net/uploads/ 71a84c9b49.png ,但我希望它显示为0123456789。有没有办法显示它的正常方向?

I want to draw some texts using Quartz. Now the app draws alt text http://www.freeimagehosting.net/uploads/71a84c9b49.png, but I want it to show as "0123456789". Is there any way to show its normal orientation?

这是我的代码:

    //set image view
 drawImage = [[UIImageView alloc] initWithImage:nil];
 drawImage.frame = self.view.frame;
 [self.view addSubview:drawImage];

 UIGraphicsBeginImageContext(self.view.frame.size);  // begin
 // current context
 CGContextRef context = UIGraphicsGetCurrentContext();

 CGContextSelectFont(context, "Courier", 40,  kCGEncodingMacRoman);
 CGFloat white[] = {1.0, 1.0, 1.0, 1.0};
 CGContextSetFillColor(context, white);
 CGContextShowTextAtPoint(context, 0, 30, "0123456789", strlen("0123456789"));

 // get image
 drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext();    // end


推荐答案

在Quartz中,图像将是上升因为它的Y轴是倒置的。

In Quartz, the image will be upside down because its Y-Axis is inverted.

iPhone的Y轴从上到下呈正值,即原点位于左上角,而在Quartz和OpenGL中,坐标与良好的旧几何相同,即原点在左下角。

iPhone's Y axis goes positive from top to bottom i.e. origin is at top left while in Quartz and OpenGL, the co-ordinates are the same way as good old geometry i.e. origin at bottom left.

以下是解决Quartz反演问题的一些代码:

Here is some code for solving Quartz inversion problem:

CGContextRef ctx = UIGraphicsGetCurrentContext();
// Tanslate and scale upside-down to compensate for Quartz's inverted coordinate system
CGContextTranslateCTM(ctx, 0.0, rect.size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);

这是一篇有趣的帖子,作者说新加坡的一个团队放弃了一个iPhone项目到期这个他们无法弄清楚的倒置问题: http://trandangkhoa.blogspot.com/2009/07/iphone-os-drawing-image-and-stupid.html

Here is an interesting post about it where the author says a team in Singapore gave up an iPhone project due to this inversion problem which they could not figure out: http://trandangkhoa.blogspot.com/2009/07/iphone-os-drawing-image-and-stupid.html

这篇关于如何在iPhone上旋转Quartz绘制的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆