IOS开发(86)之旋转图形
1 前言
使用 cgaffinetransformmakerotation/cgcontextrotatectm函数来创建一个仿射旋转变换。
2 代码实例
zyviewcontrollerview.m
[plain] - (void)drawrect:(cgrect)rect{
/* create the path first. just the path handle. */
cgmutablepathref path = cgpathcreatemutable();
/* here are our rectangle boundaries */
cgrect rectangle = cgrectmake(10.0f,10.0f, 200.0f, 300.0f);
/* add the rectangle to the path */
cgpathaddrect(path,null, rectangle);
/* get the handle to the current context */
cgcontextref currentcontext = uigraphicsgetcurrentcontext();
/* save the state of the context to revert back to how it was at this state, later */
cgcontextsavegstate(currentcontext);
//顺时针旋转45度
cgcontextrotatectm(currentcontext,(45.0f * m_pi) / 180.0f);
/* add the path to the context */
cgcontextaddpath(currentcontext, path);
/* set the fill color to cornflower blue */
[[uicolor colorwithred:0.20f green:0.60f blue:0.80f alpha:1.0f] setfill];
/* set the stroke color to brown */
[[uicolor browncolor] setstroke];
/* set the line width (for the stroke) to 5 */
cgcontextsetlinewidth(currentcontext,5.0f);
/* stroke and fill the path on the context */
cgcontextdrawpath(currentcontext, kcgpathfillstroke);
/* dispose of the path */
cgpathrelease(path);
/* restore the state of the context */
cgcontextrestoregstate(currentcontext);
}
上一篇: java环境搭建教程
下一篇: IOS开发(89)之动画之视图的缩放