Okay, the easiest way to do that is probably subclassing UIView
and use CoreGraphics for drawing. Check out the sample code from QuarzDemo.
Implement the drawInRect
-method for your custom view class. And detect the user s touches with touchesBegan
,touchesMoved
etc.
这里是一部关于绘制海滩曲线(从QarzDemo)的典型法典:
// Drawing with a white stroke color
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
// Draw them with a 2.0 stroke width so they are a bit more visible.
CGContextSetLineWidth(context, 2.0);
// Draw a bezier curve with end points s,e and control points cp1,cp2
CGPoint s = CGPointMake(30.0, 120.0);
CGPoint e = CGPointMake(300.0, 120.0);
CGPoint cp1 = CGPointMake(120.0, 30.0);
CGPoint cp2 = CGPointMake(210.0, 210.0);
CGContextMoveToPoint(context, s.x, s.y);
CGContextAddCurveToPoint(context, cp1.x, cp1.y, cp2.x, cp2.y, e.x, e.y);
CGContextStrokePath(context);
希望帮助你们开始;