Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 管理器分组问题?_Iphone_Objective C_Gdb - Fatal编程技术网

Iphone 管理器分组问题?

Iphone 管理器分组问题?,iphone,objective-c,gdb,Iphone,Objective C,Gdb,我正在开发一个裸体绘图应用程序。我试图实现撤消/重做功能,因此我告诉视图的撤消管理器在更新显示之前保存当前图像。这非常有效(是的,我知道重画/保存整个视图的效率不高,但在尝试优化代码之前要解决这个问题)。但是,正如预期的那样,当我“撤消”或“重做”时,只会反映微小的更改。我的目标是取消/重做整个手指划水动作。为此,我告诉undoManager在[ToucheSBegind]方法中使用[beginUndoGrouping],在[touchesEnded]中使用[endUndoGrouping]。这

我正在开发一个裸体绘图应用程序。我试图实现撤消/重做功能,因此我告诉视图的撤消管理器在更新显示之前保存当前图像。这非常有效(是的,我知道重画/保存整个视图的效率不高,但在尝试优化代码之前要解决这个问题)。但是,正如预期的那样,当我“撤消”或“重做”时,只会反映微小的更改。我的目标是取消/重做整个手指划水动作。为此,我告诉undoManager在[ToucheSBegind]方法中使用[beginUndoGrouping],在[touchesEnded]中使用[endUndoGrouping]。这在一段时间内是有效的,但在画了几笔之后,应用程序崩溃了,gdb退出时带有exc_bad_访问权限。根据坠机报告,这是由于内存不足

我非常感谢你能给我的任何见解

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

mouseDragged = YES;

currentPoint = [[touches anyObject] locationInView:self];

UIGraphicsBeginImageContext(drawingImageView.bounds.size);
[drawingImageView.image drawInRect:drawingImageView.bounds];

CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextSetLineWidth(ctx, drawingWidth);
[drawingColor setStroke];

CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx, previousPoint.x, previousPoint.y);
CGContextAddLineToPoint(ctx, currentPoint.x, currentPoint.y);
CGContextStrokePath(ctx);

[self.undoManager registerUndoWithTarget:drawingImageView selector:@selector(setImage:) object:drawingImageView.image];
drawingImageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
previousPoint = currentPoint;

}

尽管您可能不想解决将整个视图作为图像保存和加载的问题,但我敢肯定这正是导致应用程序崩溃的原因。每次用户的手指移动时,您都会生成另一个图像并将其添加到撤消堆栈中。无论您使用的是undo/redo操作分组,都会在那里堆积大量内存密集型映像,应用程序在某个时候会耗尽内存

撤消分组仍然适用于您,但您可能希望使用类似于
-addPoint:
的方法存储这些绘制的点,并使用
-removePoint:
方法作为撤消操作。与保存图像相比,存储点本身占用的内存要少得多

但是,如果要使用每个接触点重新绘制图像,撤消操作可能需要一段时间才能运行,因为它会重新绘制绘制轨迹中每个点的视图。您可能只想放弃撤消分组,只需注册一个撤消操作,即可在结束/取消的方法中一次删除所有点