在核心animation或核心graphics上创build简单的橡皮擦效果有多困难?

嗨,我想创build一个橡皮擦animation或核心graphics看起来像摩擦当前的内容,并添加一个新的内容,当我点击视图或button上的一个uibutton。

是否很难做到这一点,任何教程或网页链接,以显示如何做到这一点?

在这里输入图像说明

嗨,我们可以使用这个橡皮擦function核心animation在我们的应用程序如下:

CGPoint currentPoint = [touch locationInView:imgBlankView]; UIGraphicsBeginImageContext(self.view.frame.size); [imgBlankView.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, imgBlankView.frame.size.height)]; CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); CGContextSetLineWidth(UIGraphicsGetCurrentContext(),lineWidth); CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear); CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red, green, blue, 1.0); CGContextBeginPath(UIGraphicsGetCurrentContext()); CGContextSetShouldAntialias(UIGraphicsGetCurrentContext(), YES); CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint1.x, lastPoint1.y); CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y); CGContextStrokePath(UIGraphicsGetCurrentContext()); imgBlankView.image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); lastPoint1 = currentPoint; 

使用这个代码来清除你用核心animation(如圆形,矩形或任何CALayer)绘制的溺水,就像用这个代码淹没一样。

把这个代码放在你的触摸移动方法中,并根据用户触及的视图,使用此代码擦除该代码享受擦除function。