gpt4 book ai didi

iphone - 如何在此方法中实现删除/撤消

转载 作者:搜寻专家 更新时间:2023-10-30 20:12:37 27 4
gpt4 key购买 nike

我已经成功地实现了 touchesMoved 并且它正在正确地绘制线条,现在我在实现删除方法时遇到了问题,请在我缺少的地方帮助我。

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
mouseSwiped = YES;

UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.view];
currentPoint.y -= 20;


UIGraphicsBeginImageContext(self.view.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

lastPoint = currentPoint;

mouseMoved++;

if (mouseMoved == 10) {
mouseMoved = 0;
}

}

- (void) Erase
{
//NSSet *touches;
//UITouch *touch; //= (NSSet *)[touch anyObject];
CGPoint currentPoint; //= [touch locationInView:self.view];
currentPoint.y += 20;

if(mouseSwiped) {
UIGraphicsBeginImageContext(self.view.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
CGContextFlush(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}

mouseMoved--;

}

我已经在移动的触摸中成功实现了我的删除,但是当我点击一个时它会删除但是当鼠标悬停并点击左键时它会停止删除。然后需要再次单击(点击)以在新点删除。那么我怎样才能连续删除移动的触摸,

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

if (eraseBtnSelected == YES) {

if ([touch tapCount] == 1) {

[self EraseButton];

}
}
}

最佳答案

不要在事件处理方法中做任何绘制。 曾经。使用它们来编辑要绘制的事物列表,并在 -draw.. 中完成所有绘图。像 -drawRect: 这样的方法。

要删除某些东西,只需将其从要绘制的东西列表中删除,然后重新绘制有问题的 View 或图层即可。

关于iphone - 如何在此方法中实现删除/撤消,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4003328/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com