0

ここに画像の説明を入力

ユーザーが画像の上にタッチしてドラッグする

ユーザーが画像の上にタッチしてドラッグする

描画後に円を表示するこのコードがありましたが、それらを離すにはどうすればよいですか?

//UIView サークルビュー

- (void) touchesBegan:(NSSet *) touches withEvent:(UIEvent *) event
{
    NSLog(@"started");
    // Initialize a new path for the user gesture
    self.path = [UIBezierPath bezierPath];
    self.path.lineWidth = 4.0f;

        self.whiteCircleArray = [[NSMutableArray alloc]init];

    UITouch *touch = [touches anyObject];
    [self.path moveToPoint:[touch locationInView:self]];
    self.touchedEnded = FALSE;

}

- (void) touchesMoved:(NSSet *) touches withEvent:(UIEvent *) event
{
    // Add new points to the path
    NSLog(@"Moved");

    UITouch *touch = [touches anyObject];
    //NSLog(@"[touch locationInView:self] %@",NSStringFromCGPoint([touch locationInView:self]));
    [self.whiteCircleArray addObject: NSStringFromCGPoint([touch locationInView:self])];
    [self.path addLineToPoint:[touch locationInView:self]];


    //double startAngle = RADIANS(0);
    //double endAngle = RADIANS(360);

//    if ([touch locationInView:self].x <=200 )
//    {
//        [self.path addArcWithCenter:[touch locationInView:self] radius:LARGE_RADIUS startAngle:startAngle endAngle:endAngle clockwise:NO];
//    }
//    else if ([touch locationInView:self].x >=120 )
//    {
//        [self.path addArcWithCenter:[touch locationInView:self] radius:SMALL_RADIUS startAngle:startAngle endAngle:endAngle clockwise:NO];
//    }

    //[self.path addArcWithCenter:[touch locationInView:self] radius:BIG_RADIUS startAngle:startAngle endAngle:endAngle clockwise:NO];
    //[self.path addArcWithCenter:[touch locationInView:self] radius:MIDDIUM_RADIUS startAngle:startAngle endAngle:endAngle clockwise:NO];

    [self setNeedsDisplay];
}


- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"ended");
    UITouch *touch = [touches anyObject];
    //[self.path addLineToPoint:[touch locationInView:self]];
    self.locationOfTouch =[touch locationInView:self];
    self.touchedEnded = TRUE;

    //NSLog(@"white circle pos %@",self.whiteCircleArray);

    for(NSString *p in self.whiteCircleArray)
    {

        CGPoint point = CGPointFromString(p);
        NSLog(@"X=%0.1f Y=%0.1f",point.x,point.x);
    }

    [self setNeedsDisplay];
}

- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
        NSLog(@"cancelled");
    [self touchesEnded:touches withEvent:event];
}

-(void)drawTouchCircle
{
    CGContextRef ctx= UIGraphicsGetCurrentContext();
    CGContextSaveGState(ctx);
    CGContextSetLineWidth(ctx,1);

    CGContextSetRGBFillColor(ctx, 55.0/255, 255.0/255.0, 5.0/255.0, 1.0);
    CGContextSetRGBStrokeColor(ctx,0.0/255,0.0/255,0.0/255,1.0);

    for(NSString *p in self.whiteCircleArray)
    {
        CGPoint point = CGPointFromString(p);
        NSLog(@"X=%0.1f Y=%0.1f",point.x,point.x);
         CGContextAddArc(ctx, point.x, point.y, LARGE_RADIUS, 0, M_PI*2, YES);
        CGContextFillPath(ctx);
        CGContextStrokePath(ctx);
    }
}

- (void) drawRect:(CGRect)rect
{
    // Draw the path
    NSLog(@"drawRect");
    if (self.touchedEnded)
    {
         [self drawTouchCircle];
    }
    else
    {
    UIColor *strokeColor = [UIColor redColor];
    [strokeColor setStroke];
    [self.path stroke];
    }
   // [self.path  fill];
    //[self.path  closePath];

}
4

1 に答える 1

1

アルゴに距離チェックを入れる... CGPoint diff = {p2.x - p1.x, p2.y - p1.y} diff が より大きい場合、新しいポイントを追加します。

于 2013-12-05T00:51:11.760 に答える