我想用 Quartz 画一些文字.现在应用程序绘制,但我希望它显示为0123456789".有什么方法可以显示它的正常方向吗?
I want to draw some texts using Quartz. Now the app draws , 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 绘制的文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!