在核心动画或核心图形上创建简单的橡皮擦效果有多难? [英] How difficult to creat a simple eraser effect on core animation or core graphic?

查看:116
本文介绍了在核心动画或核心图形上创建简单的橡皮擦效果有多难?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想创建一个橡皮动画或核心图形,当我点击视图或按钮时,看起来像是擦掉当前内容并在uibutton上添加新内容。

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;

使用此代码擦除您使用核心动画(如圆形,矩形或任何CALayer)绘制的溺水喜欢淹没这段代码。

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.

这篇关于在核心动画或核心图形上创建简单的橡皮擦效果有多难?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆