• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 在 iOS 中使用多点触控绘图撤消

[复制链接]
菜鸟教程小白 发表于 2022-12-12 19:10:07 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我在写作时使用多点触控,所以基本上我正在做的是,我正在用手支持写作,因为通常,它是如何用户权限的,我点击了这个链接 How to ignore certain UITouch Points in multitouch sequence

一切正常,但是当我用手触摸屏幕书写时,它们的撤消有些问题,否则它工作正常。

下面是我的代码

-(void)touchesBeganNSSet *)touches withEventUIEvent *)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)touchesMovedNSSet *)touches withEventUIEvent *)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)touchesEndedNSSet *)touches withEventUIEvent *)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            
     }
   }
}

这是更好地理解我的问题的图像,我首先写了这个

enter image description here

After clicking on undo Once

单击一次撤消后,您可以在上方看到,其他部分已撤消,而不是最后一部分。所以在这方面我需要你的帮助。



Best Answer-推荐答案


m_redoArray 似乎是大爸爸,你从中汲取灵感的那个。我不明白你为什么在'touchesBegan ...'中清空它,这些数组中的一个肯定必须保持不变,否则你会从绘图开始一直丢弃东西,不是吗?

在我看来,这就是您在此处的示例中删除“ hell ”的方式..

关于ios - 在 iOS 中使用多点触控绘图撤消,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21935064/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap