CAShapeLayer面具视图

编程入门 行业动态 更新时间:2024-10-12 22:28:26
本文介绍了CAShapeLayer面具视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个问题。我在网上寻找答案,我不明白为什么不工作。我必须做一些我无法弄清楚的愚蠢错误。

I have one problem. I look for the answers on the net and I don't understand why is not working. I must do some stupid mistake which I can't figure it out.

如果我做的话:

- (void)viewDidLoad { [super viewDidLoad]; UIView * view = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 300, 400)]; view.backgroundColor = [UIColor blueColor]; [self.view addSubview:view]; }

它在屏幕上创建蓝色视图,但如果我制作

it create blue view on the screen, but if I make

- (void)viewDidLoad { [super viewDidLoad]; UIView * view = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 300, 400)]; view.backgroundColor = [UIColor blueColor]; [self.view addSubview:view]; CAShapeLayer * layer = [[CAShapeLayer alloc]init]; layer.frame = CGRectMake(10, 10, 30, 30); layer.fillColor = [[UIColor blackColor] CGColor]; view.layer.mask = layer; }

它没有显示任何内容。

it don't show anything.

如果我理解正确,它应该掩盖(10,10,30,30)?

If I understand correctly it should mask at (10,10,30,30)?

推荐答案

您需要在CAShapeLayer上设置路径:

You need to set the path on the CAShapeLayer:

- (void)viewDidLoad { [super viewDidLoad]; UIView * view = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 300, 400)]; view.backgroundColor = [UIColor blueColor]; [self.view addSubview:view]; CAShapeLayer * layer = [[CAShapeLayer alloc]init]; layer.frame = view.bounds; layer.fillColor = [[UIColor blackColor] CGColor]; layer.path = CGPathCreateWithRect(CGRectMake(10, 10, 30, 30), NULL); view.layer.mask = layer; }

更多推荐

CAShapeLayer面具视图

本文发布于:2023-11-02 03:47:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551283.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   面具   CAShapeLayer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!