Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
220 views
in Technique[技术] by (71.8m points)

ios - How to effectively process UITouches in a multitouch sequence

I am working with multitouch while writing, So basically what I am doing is, I am writing with hand support, because typically, its how user writes, I followed this link How to ignore certain UITouch Points in multitouch sequence

Everything is working fine with single touch, but their is some problem when I write with my hand touching the screen i.e multiple UItouches Below is my code

In touches began, I go through all touches and I find the touch with highest y position, 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 moved., I will only take self.trackingTouch, which I found in touches Began

My touches 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 your reference here is the image of writing with single touch and multitouch respectively

enter image description here

enter image description here

You can see that, when I write with single touch, my writing is smooth, the curves are smooth, but when I write with hand resting, I curves get jagged, as you can see in the second image.

So friends, please help me out

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Assuming the drawing code is all the same the difference is only the extra overhead of processing the extra touches. Looping to process these, looping to draw, everything is at least doubled.. So while you are processing touch and then drawing on finger #2, out here in the real world finger #1 etc is/are still moving... Be mindful that UIKit can only draw at the end of each runLoop. I don't think there is any way around this, also as I told you before, I doubt there are many people who will value the ability to draw with multiple touches, although this may well be my limited, English speaking, Australian perspective on it. Good luck


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...