ios – BezierPath和掩蔽

我想在我的视图中将UIBezierPath设置为掩码:
目标是这样的:

所以我用框架绘制视图:

CGFloat round = 80;
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(self.frame.size.width/2-105,210,60+round)];
myView.backgroundColor = [UIColor redColor];

然后尝试添加BezierMask:

UIBezierPath *aPath = [UIBezierPath bezierPath];

CGSize viewSize = CGSizeMake(myView.frame.size.width,myView.frame.size.height); //(210,80)
CGPoint startPoint = CGPointMake(myView.frame.origin.x,myView.frame.origin.y); //(279,0)

[aPath movetoPoint:startPoint]; //(279,0)

[aPath addLinetoPoint:CGPointMake(startPoint.x+viewSize.width,startPoint.y)]; //(489,0)
[aPath addLinetoPoint:CGPointMake(startPoint.x+viewSize.width,startPoint.y+viewSize.height-round)]; //(489,60)
[aPath addQuadCurvetoPoint:CGPointMake(startPoint.x,startPoint.y+viewSize.height-round) controlPoint:CGPointMake(startPoint.x+(viewSize.width/2),80)]; //(279,60) : (384,80)

[aPath closePath];

CAShapeLayer *layer = [CAShapeLayer layer];
layer.frame = myView.bounds;
layer.path = aPath.CGPath;
myView.layer.mask = layer;

[self addSubview:myView];

但在那之后我的观点正在逐渐消失.为什么?

解决方法

我猜你正在使用不正确的掩码层协调.您的遮罩层必须位于遮罩的视图内,而不是在视图的超级视图中.

尝试以下更改:

CGSize viewSize = myView.bounds.size;
CGPoint startPoint = CGPointZero;

使用这些小修改代码对我来说很合适.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...