0
我正在研究所需時間以及如何爲小學生製作繪圖板。所以它會類似畫一些東西,但只能用畫板。孩子們將能夠改變不同的顏色來繪製它。那麼我應該看哪些框架?核心圖形?還有別的嗎?任何人都可以指向一個教程或指導?提前致謝。iOS:如何讓繪圖板像繪製一些東西?
我正在研究所需時間以及如何爲小學生製作繪圖板。所以它會類似畫一些東西,但只能用畫板。孩子們將能夠改變不同的顏色來繪製它。那麼我應該看哪些框架?核心圖形?還有別的嗎?任何人都可以指向一個教程或指導?提前致謝。iOS:如何讓繪圖板像繪製一些東西?
試試這個代碼....
#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];
}
我希望這將幫助你....
我的代碼給「記憶警報」和應用程序崩潰的iPad –