如何使用uibezierpath绘制uiview的底部曲线? [英] How can i draw a bottom curve of the uiview using uibezierpath?

查看:92
本文介绍了如何使用uibezierpath绘制uiview的底部曲线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用uibezierpath在UIimageview上绘制一条底部曲线.我不知道该怎么办?

 -(void)setMaskTo:(UIView *)byRoundingCorners查看:(UIRectCorner)角落{UIBezierPath *四舍五入= [UIBezierPathbezierPathWithRoundedRect:view.bounds由RoundingCorners:cornerscornerRadii:CGSizeMake(200.0,200.0)];CAShapeLayer * shape = [[CAShapeLayer alloc] init];[shape setPath:rounded.CGPath];view.layer.mask =形状;} 

我已经这样尝试过

使用 UIBezierPath :

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

这是一个简单的 UIView 子类:

  @implementation BottomCurveView-(void)layoutSubviews {[super layoutSubviews];CGRect rect = self.bounds;CGFloat y =矩形尺寸高度-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];}@结尾 

生成上面的图像以获得200磅高的视角.

I'm tried to draw a bottom curve on UIimageview using uibezierpath. I don't know how to do that?

    - (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;
    }

i already tried like this https://imgur.com/a/WKykdyU

I expect the output of https://imgur.com/a/BqETMlc

解决方案

This should help you get going...

With a UIBezierPath:

  • move to point A
  • add quad curve to point B with control point C
  • add line to point D
  • add line to point E
  • close the path

Here's a simple UIView subclass:

@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

That produces the above image for a 200-pt tall view.

这篇关于如何使用uibezierpath绘制uiview的底部曲线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆