2011-11-12 13 views
1

私はiOS開発で初めての試みのためにペイントアプリケーションを開発しています。ボタンクリックでブラシの色を変更する方法は?

ボタンクリックでブラシの色が変わるようなカラーパレットを作成しようとしていますが、その方法はわかりません。私は既に参照アウトレットに接続されイベントを送信したUIButtonを持っていますが、私のコードは動作していません。ここ

:メソッドの上部に黒にあなたの色をリセット

- (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; 
} 

答えて

0

ストップ。

redAmt = 0; 
blueAmt = 0; 
greenAmt = 0; 
+0

ありがとうございます!出来た!! – SeongHo

0

タッチデリゲートの内部に描画しないでください。後で、OSがdrawRectを呼び出すときに描画します。後で描画する必要があることについて、タッチデリゲート内のいくつかの状態変数を設定またはキューに入れます。

関連する問題