【问题标题】:BezierPath and maskingBezierPath 和遮罩
【发布时间】:2013-05-27 12:57:56
【问题描述】:

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

所以我用框架绘制视图:

CGFloat round = 80;
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(self.frame.size.width/2-105, 0, 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];

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

【问题讨论】:

    标签: ios objective-c calayer uibezierpath bezier


    【解决方案1】:

    我猜您对遮罩层使用了不正确的协调。您的遮罩层必须位于它所遮罩的视图中,而不是位于视图的父视图中。

    试试这些改变:

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

    您的代码经过这些小修改后对我来说可以正常工作。

    【讨论】:

    • 哦,谢谢。没有意识到那必须是0,0点。谢谢。
    猜你喜欢
    • 2015-03-23
    • 2012-11-06
    • 1970-01-01
    • 2021-07-20
    • 2011-02-11
    • 2010-12-19
    • 1970-01-01
    • 1970-01-01
    • 2018-04-15
    相关资源
    最近更新 更多