从 UIView 子视图中的路径对象构建剪辑区域
我试图在 UIView 中生成一个剪切区域,该区域是从其子视图中的路径对象生成的。例如,我可能有一个包含正方形的子视图,另一个包含圆形的子视图。我希望能够在父超级视图中生成一个剪辑,它是这两个形状的联合。有人可以解释如何做到这一点吗?到目前为止我能弄清楚的是:
1 - 超级视图的drawRect:方法在其子视图的drawRect之前被调用,并且
2 - 在所有三个实例中可访问的 ContextRef 是相同的。
除此之外我很困惑。 谢谢,
霍华德
I'm trying to produce a clipping area in a UIView that's generated from path objects in its subviews. For example, I might have one subview containing a square and another containing a circle. I want to be able to produce a clip in the parent superview that's the union of both these shapes. Can someone explain how to do this? About all I've been able to figure out so far is that:
1 - the superview's drawRect: method is called before its subviews' drawRects are, and
2 - the ContextRef that's accessible in all three instances is the same.
Other than that I'm stumped.
Thanks,
Howard
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简而言之,您必须迭代所有子视图并让每个子视图修改当前上下文路径,然后将该路径设置为剪切路径。您可以请求每个视图的路径或将上下文传递给每个视图。
编辑:
当调用子视图时,您可能需要调整上下文,以便 0,0 是被调用视图的原点,而不是超级视图:
In a nutshell, you have to iterate through all the subviews and let each one modify the current context path, then set that path as the clipping path. You could ask for a path from each view or pass the context to each view.
Edit:
When calling the subview, you may want to adjust the context so that 0,0 is the origin of the called view, not the superview:
也许尝试将背景颜色设置为.clear:UIView - 矩形将消失仅租赁路径形状
Maybe try to set the background Color To .clear: the UIView - Rectangle will disappear Leasing just the path shape