iOS绘图功能
来源:互联网 发布:阿里云服务器报价 编辑:程序博客网 时间:2024/06/07 21:13
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSMutableArray *pointArray = [NSMutableArray arrayWithCapacity:1];
[_lineArry addObject:pointArray];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
// 获取当前点的位置
CGPoint point = [touch locationInView:self];
NSLog(@"point = %@", NSStringFromCGPoint(point));
// 拿到最后一个对象
NSMutableArray *pointArray = [_lineArry lastObject];
// 转换成对象类型
NSValue *pointValue = [NSValue valueWithCGPoint:point];
// 添加到数组对象中
[pointArray addObject:pointValue];
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect
{
// 拿到绘图的配置信息(绘画的属性信息)
// 通过图片得到上下文
CGContextRef context = UIGraphicsGetCurrentContext();
// 设置画笔的颜色
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
// 设置画笔的粗细
CGContextSetLineWidth(context, 2.0);
for (int i = 0; i < [_lineArry count]; i++) {
NSMutableArray *pointArry = [_lineArry objectAtIndex:i];
for (int j = 0; j < (int)pointArry.count-1; j++) {
NSValue *firstPointValue = [pointArry objectAtIndex:j];
NSValue *secondPointValue = [pointArry objectAtIndex:j + 1];
CGPoint firstPoint = [firstPointValue CGPointValue];
CGPoint secondPoint = [secondPointValue CGPointValue];
// 把笔触移动到一个点
CGContextMoveToPoint(context, firstPoint.x, firstPoint.y);
// 笔触和另一点形成一个路径(从move到point)
CGContextAddLineToPoint(context, secondPoint.x, secondPoint.y);
}
}// 绘制图形
CGContextStrokePath(context);
}
{
NSMutableArray *pointArray = [NSMutableArray arrayWithCapacity:1];
[_lineArry addObject:pointArray];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
// 获取当前点的位置
CGPoint point = [touch locationInView:self];
NSLog(@"point = %@", NSStringFromCGPoint(point));
// 拿到最后一个对象
NSMutableArray *pointArray = [_lineArry lastObject];
// 转换成对象类型
NSValue *pointValue = [NSValue valueWithCGPoint:point];
// 添加到数组对象中
[pointArray addObject:pointValue];
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect
{
// 拿到绘图的配置信息(绘画的属性信息)
// 通过图片得到上下文
CGContextRef context = UIGraphicsGetCurrentContext();
// 设置画笔的颜色
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
// 设置画笔的粗细
CGContextSetLineWidth(context, 2.0);
for (int i = 0; i < [_lineArry count]; i++) {
NSMutableArray *pointArry = [_lineArry objectAtIndex:i];
for (int j = 0; j < (int)pointArry.count-1; j++) {
NSValue *firstPointValue = [pointArry objectAtIndex:j];
NSValue *secondPointValue = [pointArry objectAtIndex:j + 1];
CGPoint firstPoint = [firstPointValue CGPointValue];
CGPoint secondPoint = [secondPointValue CGPointValue];
// 把笔触移动到一个点
CGContextMoveToPoint(context, firstPoint.x, firstPoint.y);
// 笔触和另一点形成一个路径(从move到point)
CGContextAddLineToPoint(context, secondPoint.x, secondPoint.y);
}
}// 绘制图形
CGContextStrokePath(context);
}
0 0
- iOS绘图功能
- IOS 绘图
- iOS绘图
- ios绘图
- iOS绘图
- ios 绘图
- iOS 绘图
- ios绘图
- iOS 绘图
- iOS 绘图
- IOS绘图
- iOS 绘图
- iOS绘图
- ios 绘图
- ios绘图
- ios绘图
- iOS绘图
- iOS绘图
- 文件操作、宏
- SDN与OpenFlow
- PHP开发中的小技巧(需注意)
- 保护模式总结(四)——分页机制
- 2014 编程之美初赛第一场(大数据) 解题报告
- iOS绘图功能
- 简单提示框的写法
- UVA - 10494 - If We Were a Child Again
- R语言与抽样技术学习笔记(bootstrap)
- 2014年编程之美初赛解题报告题目一
- ls -l 列表信息详解
- 无痛搞定LINUX 之 我要上网
- objectOutPutStream如果不调用reset()方法会导致内存溢出
- 终于免费用上Keynote Pages 和Numbers了