简单的画板

#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

 

posted @ 2015-03-31 23:00  曹县三胖暴打大猩猩  阅读(151)  评论(0编辑  收藏  举报