首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS:如何制作像draw之类的画板?

iOS:如何制作像draw之类的画板?
EN

Stack Overflow用户
提问于 2012-10-08 12:17:52
回答 1查看 229关注 0票数 0

我正在研究它将花费的时间和如何为小学生制作一个画板。因此,它将类似于绘制一些东西,但只使用绘图板。孩子们将能够改变不同的颜色来画它。那么我应该看哪种框架呢?核心图形?还有别的事吗?有没有人能指出教程或方向?提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-08 12:27:25

试试这段代码...

代码语言:javascript
复制
#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];
    }

我希望这能帮助你..。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12775247

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档