码迷,mamicode.com
首页 > 其他好文 > 详细

简单的画板

时间:2015-04-01 00:19:54      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:

#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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!