How difficult to creat a simple eraser effect on core animation or core graphic?

扶醉桌前 提交于 2019-12-01 02:24:09
Dhanesh

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!