Multitouch tracking issue

徘徊边缘 提交于 2019-11-28 14:01:15

You will need to debug to confirm, but it appears to be related to your logic in touchesBegan:withEvent:. In this method, you check each time there is a new touch to determine if it is the 'highest', but when the highest touch does actually change you don't seem to abort / reset any existing drawing.

Your best approach is probably using logging to determine if / when the 'highest' touch is changing and what affect that has on the in-progress line.

Also, in touchesMoved:, you don't need the for (UITouch *touch in touches) loop as you already have a reference to self.trackingTouch so you can just use it directly.

If I understood your problem correctly, you're having undesired strokes whenever the user uses multiple fingers on your canvas. Since you already have a self.trackingTouch, will it be reasonable to just ignore every other touch that is not self.trackingTouch?

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if (self.trackingTouch)
    {
        // another touch is active so we ignore this one
        return;
    }
    // ...the rest of your code
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = self.trackingTouch;
    if (![touches containsObject:touch])
    {
        // updates to touches other than self.trackingTouch
        return;
    }

    // ...process only self.trackingTouch in the rest of your code
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = self.trackingTouch;
    if (![touches containsObject:touch])
    {
        // updates to touches other than self.trackingTouch
        return;
    }

    // ...process only self.trackingTouch in the rest of your code

   self.trackingTouch = nil;
}

-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
    // ...same as touchesEnded:withEvent:
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!