如何在 iPhone 上旋转 Quartz 绘制的文字

编程入门 行业动态 更新时间:2024-10-27 08:35:45
本文介绍了如何在 iPhone 上旋转 Quartz 绘制的文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 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/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/2009/07/iphone-os-drawing-image-and-stupid.html

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

更多推荐

[db:关键词]

本文发布于:2023-03-19 06:54:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/637413.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文字   如何在   iPhone   Quartz

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!