【发布时间】:2011-12-09 06:32:28
【问题描述】:
您好,我想创建一个橡皮擦动画或核心图形,看起来像是擦掉当前内容并在我点击视图或按钮时在 uibutton 上添加新内容。
做起来难吗?有教程或网页链接来说明如何做吗?
【问题讨论】:
标签: iphone ios xcode core-animation core-graphics
您好,我想创建一个橡皮擦动画或核心图形,看起来像是擦掉当前内容并在我点击视图或按钮时在 uibutton 上添加新内容。
做起来难吗?有教程或网页链接来说明如何做吗?
【问题讨论】:
标签: iphone ios xcode core-animation core-graphics
您好,我们可以在我们的应用中使用此橡皮擦功能和核心动画,如下所示:
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 绘制的溺水),如使用此代码溺水。
将此代码放入您的触摸移动方法中,并根据用户触摸视图擦除该代码,享受该代码的擦除功能。
【讨论】: