zoukankan      html  css  js  c++  java
  • iOS 绘图

    -(id)initWithFrame:(CGRect)frame

    {

        self=[super initWithFrame:frame];

        if (self) {

            //使用self. 表示调用了set方法 retain了一次

            self.lineArray=[NSMutableArray arrayWithCapacity:1];

        }

        return self;

    }

    -(void)drawRect:(CGRect)rect

    {

        //得到上下文,即配置信息

        CGContextRef context = UIGraphicsGetCurrentContext();

        //设置颜色

        CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);

        //画笔粗细

        CGContextSetLineWidth(context, 2.0);

        //拿到小数组

        for (int i=0; i<[_lineArray count]; i++) {

            NSMutableArray * pointArray = [_lineArray objectAtIndex:i];

            //每一笔的每个点连成线

            for (int j=0; j<(int)pointArray.count - 1; j++) {

                NSValue * fistPointvalue=[pointArray objectAtIndex:j];//第一个点

                NSValue * secondPointValue=[pointArray objectAtIndex:j+1];//的二个点

                

                //转出CGPoint 类型对象

                CGPoint firstPoint=[fistPointvalue CGPointValue];

                CGPoint secondPoint=[secondPointValue CGPointValue];

                

                //把笔触移动一个点

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

                

                //笔触和另一个点 连城一个路径

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

                

            }

        }

        //执行绘制

        CGContextStrokePath(context);

        

        

    }

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

    {

        NSMutableArray *pointArray = [NSMutableArray arrayWithCapacity:1];

        //内层数组

        [_lineArray addObject:pointArray];

    }

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

    {

        UITouch *touch = [touches anyObject];

        CGPoint point = [touch locationInView:self];

         NSValue *pointValue=[NSValue valueWithCGPoint:point];

        

        NSLog(@"point=%@",NSStringFromCGPoint(point));

        //大数组

        NSMutableArray *pointArray=[_lineArray lastObject];

        

        [pointArray addObject:pointValue];

        

        //重绘

        [self setNeedsDisplay];

    }

    -(void)dealloc

    {

        [_lineArray release];

        [super dealloc];

    }

  • 相关阅读:
    WEB版一次选择多个文件进行批量上传(swfupload)的解决方案
    WEB版一次选择多个文件进行批量上传(WebUploader)的解决方案
    WEB上传大文件解决方案
    kindeditor 富文本粘贴 图片
    Kindeditor图片粘贴上传(chrome)
    PHP超大文件下载,断点续传下载
    大文件断点上传 js+php
    常见的消息映射格式总结
    常见的消息映射格式总结
    C++项目中的extern "C" {}
  • 原文地址:https://www.cnblogs.com/iOS-mt/p/4090353.html
Copyright © 2011-2022 走看看