如何使用 uibezierpath 绘制 uiview 的底部曲线?

How can i draw a bottom curve of the uiview using uibezierpath?

我尝试使用 uibezierpath 在 UIimageview 上绘制底部曲线。我不知道该怎么做?

    - (void)setMaskTo:(UIView*)view byRoundingCorners: 
   (UIRectCorner)corners
   {
      UIBezierPath *rounded = [UIBezierPath 
      bezierPathWithRoundedRect:view.bounds

      byRoundingCorners:corners

      cornerRadii:CGSizeMake(200.0, 200.0)];
      CAShapeLayer *shape = [[CAShapeLayer alloc] init];
      [shape setPath:rounded.CGPath];
      view.layer.mask = shape;
    }

我已经试过了https://imgur.com/a/WKykdyU

我期待 https://imgur.com/a/BqETMlc

的输出

这应该可以帮助您开始...

UIBezierPath:

  • 移动到点A
  • 将四边形曲线添加到点 B 和控制点 C
  • 向点添加线 D
  • 向点添加线 E
  • 关闭路径

这是一个简单的 UIView 子类:

@implementation BottomCurveView

- (void)layoutSubviews {
    [super layoutSubviews];

    CGRect rect = self.bounds;
    CGFloat y = rect.size.height - 80.0;
    CGFloat curveTo = rect.size.height;

    UIBezierPath *myBez = [UIBezierPath new];
    [myBez moveToPoint:CGPointMake(0.0, y)];
    [myBez addQuadCurveToPoint:CGPointMake(rect.size.width, y) controlPoint:CGPointMake(rect.size.width / 2.0, curveTo)];
    [myBez addLineToPoint:CGPointMake(rect.size.width, 0.0)];
    [myBez addLineToPoint:CGPointMake(0.0, 0.0)];
    [myBez closePath];

    CAShapeLayer *maskForPath = [CAShapeLayer new];
    maskForPath.path = myBez.CGPath;
    [self.layer setMask:maskForPath];
}

@end

为 200 磅高的视图生成上面的图像。