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

How to rotate text drawn by Quartz on iPhone(如何在 iPhone 上旋转 Quartz 绘制的文字)
本文介绍了如何在 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.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 绘制的文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How to stop UIBarButtonItem text from truncating?(如何阻止UIBarButtonItem文本被截断?)
java.lang.IllegalStateException: SimpleTypeImpl should not be created for error type(异常:不应为错误类型创建SimpleTypeImpl)
Android Adding a button with multiline text inside MaterialButtonToggleGroup doesn#39;t work(Android在MaterialButtonToggleGroup中添加多行文本的按钮不起作用)
Switch Status Bar Text Color / setAppearanceLightStatusBars of WindowController is not working as expected(开关状态栏文本颜色/设置外观WindowController的LightStatusBars未按预期工作)
How to change status bar icon and text color in flutter based on theme been set?(如何根据已设置的主题更改颤动中的状态栏图标和文本颜色?)