我试图在 iOS 中为我的绘图应用程序执行撤消功能。我的方法是在每次绘图(直线、直线、正方形、圆形)之后,将绘图添加到数组中,以便我可以在撤消时弹出/删除数组的 lastObjectIndex,然后将数组的内容重新绘制到图像视图。我正在使用 NSMutableArray 和 UIImage 并使用 UIGraphicsGetImageFromCurrentImageContext。我的问题是,如何将所有图像数组显示到一个 UIImageView 中?
这是我的代码:
imgArray = [[NSMutableArray alloc] init];
UIImage *tempImg = [[UIImage alloc] init];
tempImg = UIGraphicsGetImageFromCurrentImageContext();
[imgArray addObject:tempImg];
UIGraphicsEndImageContext();
UIGraphicsBeginImageContext(mainImage.frame.size);
[mainImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) blendMode:kCGBlendModeNormal alpha:1.0];
[tempImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) blendMode:kCGBlendModeNormal alpha:opacity];
mainImage.image = tempImg; //UIGraphicsGetImageFromCurrentImageContext();
tempImage.image = nil;
UIGraphicsEndImageContext();