簡體   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