2012-05-09 4 views
0

メインビューのサブビュー内のUIImageViewでペイントできるiOS 5アプリケーションを開発しています。線の最初の30ピクセルをペイントするときに、ストロークに従わない。しかし、本当にまれなのは、ImageViewのサイズを460x320のすべてのスクリーンサイズにすると(イメージビュー全体が表示されていないにもかかわらず、内部のビューよりも大きいためです)、それはうまく動作します。だから、おそらく解決策があります。iOSアプリケーションでのエラーペイント

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    mouseSwiped = NO; 
    UITouch *touch = [touches anyObject]; 

    if ([touch tapCount] == 2) { 
     drawImage.image = nil; 
     return; 
    } 

    lastPoint = [touch locationInView:self.view]; 
    lastPoint.y -= 10; 
} 

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    mouseSwiped = YES; 
    UITouch *touch = [touches anyObject]; 
    CGPoint currentPoint = [touch locationInView:self.drawImage]; 
    currentPoint.y -= 10; // only for 'kCGLineCapRound' 
    UIGraphicsBeginImageContext(self.drawImage.frame.size); 

    [drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)]; //originally self.frame.size.width, self.frame.size.height)]; 
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); //kCGLineCapSquare, kCGLineCapButt, kCGLineCapRound 
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5); // for size 
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 1.0, 0.0, 1.0); //values for R, G, B, and Alpha 
    CGContextBeginPath(UIGraphicsGetCurrentContext()); 
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); 
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y); 
    CGContextStrokePath(UIGraphicsGetCurrentContext()); 
    drawImage.image = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    lastPoint = currentPoint; 

    mouseMoved++; 

    if (mouseMoved == 10) { 
     mouseMoved = 0; 
    } 
} 

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {  
    UITouch *touch = [touches anyObject]; 

    if ([touch tapCount] == 2) { 
     drawImage.image = nil; 
     return; 
    } 
    if(!mouseSwiped) { 
     //if color == green 
     UIGraphicsBeginImageContext(self.drawImage.frame.size); 
     [drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)]; //originally self.frame.size.width, self.frame.size.height)]; 
     CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); //kCGLineCapSquare, kCGLineCapButt, kCGLineCapRound 
     CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5); 
     CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 1.0, 0.0, 1.0); 
     CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); 
     CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); 
     CGContextStrokePath(UIGraphicsGetCurrentContext()); 
     CGContextFlush(UIGraphicsGetCurrentContext()); 
     drawImage.image = UIGraphicsGetImageFromCurrentImageContext(); 
     UIGraphicsEndImageContext(); 
    } 
} 

That's what I get

答えて

1

問題は最初touchesMoved:は、APIによって遅延されていることである:それは私のコードです。誰もこの問題をまだ解決できていないのは確かです。

http://radar.apple.com

でバグレポートを提出してくださいあなたのケースでは本当の問題はしかし、単純なミスです:あなたはtouchesBegan:touchesMoved:に二つの異なる座標系を使用しています。

touchesBegan:

lastPoint = [touch locationInView:self.view]; 
           ////////// 

touchesMoved:

CGPoint currentPoint = [touch locationInView:self.drawImage]; 
              /////////////// 
+0

申し訳ありませんが、私は今それを読んで、文を終了しませんでした。 :) –

+0

申し訳ありません、今私は文を終えました:)それを今読んで、あなたは理解すると思います! –

+0

@MartiSerraVivancosこの動作についてバグレポートを提出してください。十分な人が不平を言うのでなければ、Appleはおそらくそれを修正しないでしょう。 – fzwo

関連する問題