我在写作时使用多点触控,所以基本上我正在做的是,我正在用手支持写作,因为通常,它是如何用户权限的,我点击了这个链接 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
}
}
}
这是更好地理解我的问题的图像,我首先写了这个
单击一次撤消后,您可以在上方看到,其他部分已撤消,而不是最后一部分。所以在这方面我需要你的帮助。
m_redoArray 似乎是大爸爸,你从中汲取灵感的那个。我不明白你为什么在'touchesBegan ...'中清空它,这些数组中的一个肯定必须保持不变,否则你会从绘图开始一直丢弃东西,不是吗?
在我看来,这就是您在此处的示例中删除“ hell ”的方式..
关于ios - 在 iOS 中使用多点触控绘图撤消,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21935064/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |