iOS:如何制作一个像画东西一样的画板?

标签 ios ipad

我正在研究需要的时间以及如何为小学生制作绘图板。所以它会类似于绘制一些东西,但只能使用绘图板。 children 将能够改变不同的颜色来绘制它。那么我应该看哪些框架?核心显卡?还有别的吗?任何人都可以指出教程或方向吗?提前致谢。

最佳答案

试试这个代码....

#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];
    }

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

关于iOS:如何制作一个像画东西一样的画板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12775247/

相关文章:

用于测试 HTTP 响应代码和时间的 iOS App

ios - 是否可以在不使用完成 block 的情况下在 UIView 上执行多个动画

ios - iPhone 4、5、5s 和 6+ 模拟器错位节点

iphone - 如何在 Cocos2d 中重复(连续)TileMap?

objective-c - 如何动画和旋转图像?

ios - 我怎么知道 UITableView 何时完成重新加载

ios - 运行时属性边框颜色

ios - 仅在 iOS 7 中点击单元格时,tableview 单元格中的标签文本消失

iphone - 在 iOS 应用程序中打开网页

jquery - 更改焦点表单元素时禁用滚动 ipad Web 应用程序