How to get all coordinate points (X and Y) in ios

I am writing an application that allows the user to draw whatever they need in a view. While they are drawing, I am sending the coordinate values ​​simultaneously to the web using Json, and I am drawing the same chart on the web. When I draw slowly, I get all coordinate values ​​like this.

{"XY":["92,240","94,240","96,240","97,240","98,240","99,240","100,240","102,240","103,240","104,240","104,240","105,240","106,240","107,240","108,240","108,240","110,240","110,240","112,240","112,240","114,240","115,240","116,240","117,240","118,240","120,240","120,240","120,240","122,240","122,240","124,240","124,240","126,240"]}

      

But when I draw quickly, I get the drawing I want, but there are a lot of coordinate values ​​missing.

{"XY":["96,320","117,302","170,262","252,208"]}

      

The following code I used to implement it.

@implementation PJRSignatureView
{
    UIBezierPath *beizerPath;
    UIImage *incrImage;
    CGPoint points[10];
    uint control;
}
- (void)drawRect:(CGRect)rect
{
    [incrImage drawInRect:rect];
    [beizerPath stroke];

    // Set initial color for drawing

    UIColor *fillColor = INITIAL_COLOR;
    [fillColor setFill];
    UIColor *strokeColor = INITIAL_COLOR;
    [strokeColor setStroke];
    [beizerPath stroke];

}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if ([lblSignature superview]){
        [lblSignature removeFromSuperview];
    }
    rectArray = [[NSMutableArray alloc] init];
    control = 0;
    UITouch *touch = [touches anyObject];
    points[0] = [touch locationInView:self];

    CGPoint startPoint = points[0];
    CGPoint endPoint   = CGPointMake(startPoint.x + 1.5, startPoint.y
                              + 2);



   [beizerPath moveToPoint:startPoint];
        NSLog(@"myPoint = %@", [NSValue valueWithCGPoint:endPoint]);
        NSLog(@"beizerPath    :%@",beizerPath);
    [beizerPath addLineToPoint:endPoint];
     NSLog(@"beizerPath end:%@",beizerPath);
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint touchPoint = [touch locationInView:self];
    control++;
    points[control] = touchPoint;

    if (control == 4)
    {
        points[3] = CGPointMake((points[2].x + points[4].x)/2.0, (points[2].y + points[4].y)/2.0);

        [beizerPath moveToPoint:points[0]];
        [beizerPath addCurveToPoint:points[3] controlPoint1:points[1] controlPoint2:points[2]];

        [self setNeedsDisplay];

        points[0] = points[3];
        points[1] = points[4];
        control = 1;
    }
       NSLog(@"beizerPathmove:%@",beizerPath);
    NSString *rect_xy = [NSString stringWithFormat:@"%.f,%.f",touchPoint.x,touchPoint.y];

    [rectArray addObject:rect_xy];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self drawBitmapImage];
    [self setNeedsDisplay];
    [beizerPath removeAllPoints];

    NSMutableDictionary *rectDict = [[NSMutableDictionary alloc]init];
    [rectDict setValue:rectArray forKey:@"XY"];
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:rectDict options:0 error:nil];

    // Checking the format
    NSLog(@"%@",[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]);
    control = 0;
}

      

How do I find all coordinate values ​​even when I am drawing quickly?

+3


source to share


2 answers


Apple products dispatch touch events at regular intervals. So if you draw / write something slowly to get all the coordinate values, if you draw / write quickly you will be smaller than some of them. And apply the same function on the network that you used. Hopefully this will be fixed now.



0


source


The system sends touch events at a specified interval. If you move slowly, you get more, but quickly, you get less. You can't get more if you move fast. But you also don't need it anymore. You just need to draw a line between the points, regardless of whether the distance between them is small or large.



0


source







All Articles