画图3

画板画图


{

UIImageView *_canvasImageView;

//起点

CGPoint _startPoint;

}

- (void)viewDidLoad {

[super viewDidLoad];

_canvasImageView = [[UIImageView alloc] init];

_canvasImageView.frame = self.view.frame;

[self.view addSubview:_canvasImageView];

}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

//开始触摸记录初始触摸点坐标

_startPoint = [[touches anyObject] locationInView:_canvasImageView];

}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

//移动点坐标

CGPoint movePoint = [[touches anyObject] locationInView:_canvasImageView];

//释放池

@autoreleasepool {

UIGraphicsBeginImageContext(_canvasImageView.bounds.size);

[_canvasImageView drawRect:_canvasImageView.bounds];

CGContextRefcontext = UIGraphicsGetCurrentContext();

CGContextSetLineWidth(context, 20);

CGContextSetRGBStrokeColor(context, 0, 1, 0.5, 1);

CGContextSetLineCap(context,kCGLineCapRound);

CGContextSetLineJoin(context,kCGLineJoinRound);

CGContextMoveToPoint(context,_startPoint.x,_startPoint.y);

CGContextAddLineToPoint(context, movePoint.x, movePoint.y);

CGContextStrokePath(context);

UIImage *image  =UIGraphicsGetImageFromCurrentImageContext();

_canvasImageView.image = image;

UIGraphicsEndPDFContext();

_startPoint = movePoint;

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌。在这里你可以看...
    F麦子阅读 5,147评论 5 13
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥ios动画全貌。在这里你可以看...
    每天刷两次牙阅读 8,578评论 6 30
  • -- iOS事件全面解析 概览 iPhone的成功很大一部分得益于它多点触摸的强大功能,乔布斯让人们认识到手机其实...
    翘楚iOS9阅读 3,014评论 0 13
  • Quartz2D以及drawRect的重绘机制字数1487 阅读21 评论1 喜欢1一、什么是Quartz2D Q...
    PurpleWind阅读 810评论 0 3
  • { 11、核心动画 需要签协议,但是系统帮签好 一、CABasicAnimation 1、创建基础动画对象 CAB...
    CYC666阅读 1,591评论 2 4