Отмена с мультитач рисования в iOS

Я работаю с мультитач во время написания, так что, в основном, я пишу с ручной поддержкой, потому что, как правило, это как права пользователя, я следовал по этой ссылкеКак игнорировать определенные точки UITouch в мультитач-последовательности

Все работает нормально, но возникает проблема с отменой, когда я пишу рукой, касаясь экрана, в противном случае он работает нормально.

Ниже мой код

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch* topmostTouch = self.trackingTouch;
    for (UITouch *touch in touches)
    {
        ctr = 0;

        touchStartPoint1 = [touch locationInView:self];


        [m_undoArray removeAllObjects];
        [m_redoArray removeAllObjects];
        [m_parentRedoArray removeAllObjects];


        if(!topmostTouch || [topmostTouch locationInView:self].y > touchStartPoint1.y)
        {
            topmostTouch = touch;
            pts[0] = touchStartPoint1;
        }
    }


    if (self.trackingTouch != nil && self.trackingTouch != topmostTouch)  //              ![touches containsObject:self.trackingTouch])
    {
        [self discardDrawing];

    }

    self.trackingTouch = topmostTouch;
}

-(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]];

        CGPathRef cgPath = self.currentPath.path.CGPath;
        mutablePath = CGPathCreateMutableCopy(cgPath);

        [m_undoArray addObject:self.currentPath];
        [self setNeedsDisplay];


        pts[0] = pts[3];
        pts[1] = pts[4];
        ctr = 1;
    }
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{    
    for (UITouch *touch in touches)
    {
        if(touch == self.trackingTouch)
        {
             [m_parentUndoArray addObject:[NSArray arrayWithArray:m_undoArray]];                
        }          
   }
}


-(void)undoButtonClicked
{     
    NSMutableArray *undoArray = [m_parentUndoArray lastObject];

    NSLog(@"%@",undoArray);

    [m_parentUndoArray removeLastObject];
    [m_parentRedoArray addObject:undoArray];
     m_drawStep = UNDO;  

    [self setNeedsDisplay];    

}


- (void)drawRect
{
   I have different cases here, I am showing Of Undo

   for(int i = 0; i<[m_parentUndoArray count];i++)
   {
       NSMutableArray *undoArray = [m_parentUndoArray objectAtIndex:i];
       NSLog(@"%@",undoArray);

      for(int i =0; i<[undoArray count];i++)
      {
         DrawingPath *drawPath = [undoArray objectAtIndex:i];
         GPathRef path = drawPath.path.CGPath;
         mutablePath = CGPathCreateMutableCopy(path);

         //Draw into CgLayer            
     }
   }
}

Вот изображение, чтобы лучше понять мою проблему, я сначала написал это

После того, как вы нажали «Отменить» один раз, вы увидите, что какая-то другая часть была отменена, а не последняя. Поэтому мне нужна ваша помощь в этом отношении.

Ответы на вопрос(2)

Ваш ответ на вопрос