Hi i will like to create an eraser animation or core graphic that looks like rubbing away the current content and add in a new content on a uibutton when i tapped on the view or button.
is it tough to do it ?, any tutorial or web link to show how to do it ?
Hi, we can use this eraser functionality with core animation in our app like below:
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;
Use this code for erase the drowning which you draw with the core animation like circle ,rectangle or any CALayer like drowning with this code.
Put this code in your touch move method and as per user touches on the view it erase that on with this code enjoy erasing functionality with this code.
来源:https://stackoverflow.com/questions/8441916/how-difficult-to-creat-a-simple-eraser-effect-on-core-animation-or-core-graphic