繁体   English   中英

如何使用 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
  • 用控制点C将四边形曲线添加到点B
  • 将线添加到点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 磅高的视图生成了上面的图像。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM