Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问博主,内部一个CAShapeLayer,和你的内部N多个CAShapeLayer有什么不同吗?你为什么选择N个CAShapeLayer呢? #1

Open
FengDeng opened this issue Jan 18, 2016 · 11 comments

Comments

@FengDeng
Copy link

No description provided.

@bb-coder
Copy link
Owner

画板可以绘制多个线条,所以我很显然的用了多个CAShapeLayer,并且我们的画板是支持回滚和重做的,这些功能可能更加需要依赖多个线形图层的支持。如果后面加入画笔功能,可以画不同颜色、形状,那么多个图层也是唯一的选择。

@FengDeng
Copy link
Author

嗯,的确是这样 我加入了画笔和颜色。但是问题出现在,很多个CAShapeLayer,我不知道橡皮擦怎么加。如果用self.path.strokeWithBlendMode(CGBlendMode.Clear, alpha: 1.0),则无法擦掉另一CAShapeLayer的。不知道楼主有什么办法吗?

@bb-coder
Copy link
Owner

实际上橡皮擦也是绘制出的形状,只不过它的颜色与背景一样,并且它也可以回滚和重做。这样实际上就是覆盖了之前图层,而不是擦除。对吧?

@FengDeng
Copy link
Author

嗯 这是没有办法的办法了。 如果这样做的话,那画布就不能有背景图片了。。。。。

@bb-coder
Copy link
Owner

可以存在背景图片,用你的背景图生成一个颜色,然后用一个使用这个颜色的layer做为橡皮。[[UIColor alloc]initWithPatternImage:],注意背景图片的CTM翻转。

@MindedCoder
Copy link

要是在有背景图片的情况下,再插入图片在背景图片上面 这时橡皮擦怎么去实现?

@bb-coder
Copy link
Owner

如果插入的图片大于等于背景图,直接用插入的图当橡皮擦颜色。如果插入的图片比背景图小,将背景图和插入的图片从新截图出一个新的融合背景来作为橡皮擦颜色。

@bb-coder
Copy link
Owner

可以参考 #3 的思路保存位图。

@bb-coder bb-coder reopened this Apr 26, 2016
@MindedCoder
Copy link

"注意背景图片的CTM翻转" 能简单提一下具体如何翻转么

@MindedCoder
Copy link

#3这个保存图片的不适合我们业务

@wkowko
Copy link

wkowko commented Apr 18, 2017

你们好 怎样实现橡皮擦功能啊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants