ios绘图函数异常
2014-06-30 14:34
190 查看
在使用ios的绘图函数时,发现坐标总是上下颠倒,原因如下
Side Effects of Drawing with Different Coordinate Systems
Some rendering oddities are brought to light when you draw an object with with reference to the default coordinate system of one drawing technology and then render it in a graphics context of the other. You may want to adjust your code to account
for these side effects.
Arcs and Rotations
If you draw a path with functions such as
CGContextAddArc and
CGPathAddArc and assume a LLO coordinate system, then you need to flip the CTM to render the arc correctly in a UIKit view. However, if you use the same function to create an arc with points located in a ULO coordinate system and
then render the path in a UIKit view, you’ll notice that the arc is an altered version of its original. The terminating endpoint of the arc now points in the opposite direction of what that endpoint would do were the arc created using the
UIBezierPath class. For example, a downward-pointing arrow now points upward (as shown in Figure 1-5), and the direction in which the arc “bends” is also different. You must change the direction of Core Graphics-drawn arcs to account
for the ULO-based coordinate system; this direction is controlled by the
startAngle and endAngle parameters of those functions.
Figure 1-5 Arc rendering in Core Graphics versus UIKit
You can observe the same kind of mirroring effect if you rotate an object (for example, by calling
CGContextRotateCTM). If you rotate an object using Core Graphics calls that make reference to a ULO coordinate system, the direction of the object when rendered in UIKit is reversed. You must account for the different directions
of rotation in your code; with CGContextRotateCTM, you do this by inverting the sign of the
angle parameter (so, for example, a negative value becomes a positive value).
上述方案要求开发者自行注意方向,另一种解决方案是多做一次y轴flip变换(from http://stackoverflow.com/questions/16974258/cgcontextaddarc-counterclockwise-instead-of-clockwise)
Side Effects of Drawing with Different Coordinate Systems
Some rendering oddities are brought to light when you draw an object with with reference to the default coordinate system of one drawing technology and then render it in a graphics context of the other. You may want to adjust your code to account
for these side effects.
Arcs and Rotations
If you draw a path with functions such as
CGContextAddArc and
CGPathAddArc and assume a LLO coordinate system, then you need to flip the CTM to render the arc correctly in a UIKit view. However, if you use the same function to create an arc with points located in a ULO coordinate system and
then render the path in a UIKit view, you’ll notice that the arc is an altered version of its original. The terminating endpoint of the arc now points in the opposite direction of what that endpoint would do were the arc created using the
UIBezierPath class. For example, a downward-pointing arrow now points upward (as shown in Figure 1-5), and the direction in which the arc “bends” is also different. You must change the direction of Core Graphics-drawn arcs to account
for the ULO-based coordinate system; this direction is controlled by the
startAngle and endAngle parameters of those functions.
Figure 1-5 Arc rendering in Core Graphics versus UIKit
You can observe the same kind of mirroring effect if you rotate an object (for example, by calling
CGContextRotateCTM). If you rotate an object using Core Graphics calls that make reference to a ULO coordinate system, the direction of the object when rendered in UIKit is reversed. You must account for the different directions
of rotation in your code; with CGContextRotateCTM, you do this by inverting the sign of the
angle parameter (so, for example, a negative value becomes a positive value).
上述方案要求开发者自行注意方向,另一种解决方案是多做一次y轴flip变换(from http://stackoverflow.com/questions/16974258/cgcontextaddarc-counterclockwise-instead-of-clockwise)
CGContextSaveGState(ctx); CGContextTranslateCTM(ctx, 0.0, self.bounds.size.height); CGContextScaleCTM(ctx, 1.0, -1.0); // Draw... CGContextRestoreGState(ctx);
相关文章推荐
- IOS开发之绘图函数
- 对象的成员函数中抛出的异常
- 我的理解:在有返回值的函数内是否应该使用异常处理?欢迎大家斧正
- Matlab7.0学习笔记(6)基本的绘图函数
- 异常详细信息: System.Data.SqlClient.SqlException:过程或函数 需要参数 但未提供该参数。
- 关于 ORA-00937: 非单组分组函数 异常
- 为MicroWindows添加透明绘图函数
- matlab绘图函数
- 一组JavaScript绘图函数
- 学习用于异常处理的terminate()函数
- Item 39. 异常安全之函数(Exception Safe Functions)
- ActionScript绘图函数收集
- 函数签名不一致引发异常
- API之绘图函数
- [转]C语言图形编程(三) -绘图函数①
- Item 39. 异常安全之函数(Exception Safe Functions)
- 1.1.40. stl中的pop_back和 pop函数为什么不带返回值?--为了不减弱 异常安全性-
- 一组JavaScript绘图函数
- 常用 API 函数(8): 绘图函数
- 常用 API 函数: 绘图函数