基于CGRect屏蔽UIView [英] masking UIView based on CGRect

查看:130
本文介绍了基于CGRect屏蔽UIView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看图片:

Look at the image please :

我有UIView和CGRect。我必须检查CGRect覆盖UIView的位置,然后在与交叉点相对的区域设置掩码。所以它是图像中的蓝色部分。如何实现呢?
我知道有CGContextClipToMask,但我不知道如何使用 - 有人可以帮助我的示例代码?是CGContextClipToMask好方向吗?

I have UIView and CGRect. I have to check where CGRect overlays UIView and then set the mask on the area which is "opposed" to intersection. So it's blue part in the image. How to achieve that? I know there's CGContextClipToMask but I have no idea how to use that - could someone help me with example code? Is CGContextClipToMask good direction?

谢谢!

推荐答案

您可以为UIView的图层分配遮罩图层。

You can assign mask layer to your UIView's layer.

CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
view.layer.mask = maskLayer;

CGPathRef path = CGPathCreateMutable();
// Construct path and set it.
[maskLayer setPath:path];
CGPathRelease(path);

[maskLayer release];

文档: CALayer reference

这篇关于基于CGRect屏蔽UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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