【发布时间】:2011-11-12 04:05:12
【问题描述】:
我正在为我的 iOS 开发第一次尝试开发一个绘画应用程序。
我正在尝试制作一个调色板,可以在单击按钮时更改我的画笔颜色,但我不知道如何。我已经有 UIButtons 连接到它的参考插座并发送事件,但我的代码不起作用。
这里:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
touchSwiped = YES;
redAmt = 0;
blueAmt = 0;
greenAmt = 0;
UITouch *touch = [touches anyObject];
CGPoint currentTouch = [touch locationInView:self.view];
currentTouch.y -= 20;
UIGraphicsBeginImageContext(self.view.frame.size);
[touchDraw.image drawInRect:CGRectMake(0, 0, touchDraw.frame.size.width, touchDraw.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 35.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), redAmt, blueAmt, greenAmt, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), endingPoint.x, endingPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentTouch.x, currentTouch.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
touchDraw.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
endingPoint = currentTouch;
touchMoved++;
if (touchMoved == 10) {
touchMoved = 0;
}
}
-(IBAction)blackInk:(id)sender
{
redAmt = 0;
blueAmt = 0;
greenAmt = 0;
}
-(IBAction)blueInk:(id)sender
{
redAmt = 0;
blueAmt = 0;
greenAmt = 1;
}
-(IBAction)redInk:(id)sender
{
redAmt = 1;
blueAmt = 1;
greenAmt = 0;
}
-(IBAction)greenInk:(id)sender
{
redAmt = 0;
blueAmt = 1;
greenAmt = 0;
}
【问题讨论】:
标签: iphone objective-c ios ipad core-graphics