首页 > 其他 > 详细

简单的画板

时间:2015-04-01 00:17:53      阅读:162      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!