我正在研究需要的时间以及如何为小学生制作绘图板。所以它会类似于绘制一些东西,但只能使用绘图板。 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/