How to efficiently process UIT files in a multi-touch sequence

I am working with multitouch while writing. So basically I do this, I write with hand support, because, as a rule, as he writes, I followed this link How to ignore certain UITouch points in a multitouch sequence

Everything works fine with one touch, but their problem occurs when I write with my hand, touching the screen, for example, with several UItouches Below is my code

The touches started, I look through all the touches, and I find the touch with the highest position y, below is my code

Below is my code

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch* topmostTouch = self.trackingTouch; for (UITouch *touch in touches) { ctr = 0; touchStartPoint1 = [touch locationInView:self]; if(!topmostTouch || [topmostTouch locationInView:self].y > touchStartPoint1.y) { topmostTouch = touch; pts[0] = touchStartPoint1; } } self.trackingTouch = topmostTouch; } 

In touches moves., I will take only self.trackingTouch, which I found in touches. Began

My Strokes Moved code below

 -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { if(self.trackingTouch== nil) { return; } CGPoint p = [self.trackingTouch locationInView:self]; ctr++; pts[ctr] = p; if (ctr == 4) { pts[3] = midPoint(pts[2], pts[4]); self.currentPath = [[DrawingPath alloc] init]; [self.currentPath setPathColor:self.lineColor]; self.currentPath.pathWidth = [NSString stringWithFormat:@"%f",self.lineWidth]; [self.currentPath.path moveToPoint:pts[0]]; [self.currentPath.path addCurveToPoint:pts[3] controlPoint1:pts[1] controlPoint2:pts[2]]; [self setNeedsDisplay]; pts[0] = pts[3]; pts[1] = pts[4]; ctr = 1; } } 

For reference, here is the image of the image with one touch and multi-touch, respectively

enter image description here

enter image description here

You can see that when I write with one touch, my writing is smooth, the curves are smooth, but when I write with manual peace, my curves become jagged, as you can see in the second image.

So friends, please help me.

+2
ios core-graphics uibezierpath uiresponder uitouch
Feb 22 '14 at 9:18
source share
2 answers

Assuming the drawing code is all the same, the difference is just the extra overhead of processing extra strokes. Looping to process them, looping to draw, everything is at least doubled. So, while you are processing the touch, and then draw on finger number 2, here in the real world finger number 1, etc. Still moving ... Be careful that UIKit can only draw at the end of each runLoop. I don’t think there is any way around this, also, as I already told you, I doubt that there are many people who will appreciate the ability to draw with a few touches, although this may well be my limited, English-speaking Australian perspective. This . Good luck.

+1
Feb 22 '14 at 23:46
source share

I finally solved my problem

Here is the code

 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch* topmostTouch = self.trackingTouch; for (UITouch *touch in touches) { touchStartPoint1 = [touch locationInView:self]; if(!topmostTouch || [topmostTouch locationInView:self].y > touchStartPoint1.y) { ctr = 0; topmostTouch = touch; pts[0] = touchStartPoint1; } } self.trackingTouch = topmostTouch; } 

The problem was very simple, just set ctr = 0 inside the check like this ..

0
Feb 24 '14 at 14:45
source share



All Articles