标签:
#import "MyView.h" @interface MyView () { CGMutablePathRef pathRef; } @end @implementation MyView -(id)initWithCoder:(NSCoder *)aDecoder { if (self=[super initWithCoder:aDecoder]) { pathRef=CGPathCreateMutable(); } return self; } -(void)drawRect:(CGRect)rect { CGContextRef contextRef=UIGraphicsGetCurrentContext(); CGContextAddPath(contextRef, pathRef); CGContextStrokePath(contextRef); } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint p=[touches.anyObject locationInView:self]; CGPathMoveToPoint(pathRef, nil, p.x, p.y); } -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint p=[touches.anyObject locationInView:self]; CGPathAddLineToPoint(pathRef, nil, p.x, p.y); [self setNeedsDisplay]; } @end
标签:
原文地址:http://www.cnblogs.com/thbbsky/p/4382411.html