iOS:如何制作一个绘制画板,就像画一些东西?

时间:2012-10-08 04:17:52

标签: ios ipad

我正在研究它将花费的时间以及如何为小学生制作绘图板。所以它会有类似的东西,但只有画板。孩子们将能够改变不同的颜色来绘制它。那么我应该看看哪些框架?核心图形?还有别的吗?任何人都可以指向教程或方向吗?提前谢谢。

1 个答案:

答案 0 :(得分:1)

试试这个代码......

#pragma mark touches stuff...

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        UITouch *touch = [touches anyObject];
        lastTouch = [touch locationInView:imageView];

       }

    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
        UITouch *touch = [touches anyObject];
        currentTouch = [touch locationInView:imageView];

        CGColorRef strokeColor = [UIColor brownColor].CGColor;
        UIGraphicsBeginImageContext(imageView.frame.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
        [imageView.image drawInRect:CGRectMake(0, 0, imageView.frame.size.width, imageView.frame.size.height)];
        CGContextSetLineCap(context, kCGLineCapRound);
        CGContextSetLineWidth(context,10); // 10 is the pen size

     CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), [UIColor brownColor].CGColor); // this will be colour u need to change as required 
                CGContextSetBlendMode(context,kCGBlendModeDarken );



        CGContextBeginPath(context);
        CGContextMoveToPoint(context, lastTouch.x, lastTouch.y);
        CGContextAddLineToPoint(context, currentTouch.x, currentTouch.y);
        CGContextStrokePath(context);
        imageView.image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

        lastTouch = [touch locationInView:imageView];
    }

    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    {
        UITouch *touch = [touches anyObject];
        lastTouch = [touch locationInView:imageView];
    }

我希望这对你有帮助....