How can I create a non-animation UIView / UIImageView curve?

How can I create a uiview that looks like this, as well as its subview to get the same effect. After searching the net, I found that CALayer can do this, but I don't have enough knowledge about it. Please help me. Thanks in advance.

How

+4
source share
2 answers

Under my levels and my understanding, I made some encoding that can help you .. If not, please ignore it.

1st Create a custom view from a new file

ViewController view UIView CustomView. MainStoryboard.storyboard "". ( + + 3) CustomView.

- (void)drawRect:(CGRect)rect
{
  // Drawing code
  UIImage *imageRecipe =[UIImage imageNamed:@"statement_card_1.png"];
  UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0 ,0 ,290, 200)];
  imgView.image = imageRecipe;
  [self addSubview:imgView];

  CGPoint secondPoint = CGPointZero;
  CGPoint point1 = CGPointZero;
  CGPoint initial = CGPointZero;

  UIBezierPath *aPath = [UIBezierPath bezierPath];

  initial = CGPointMake(30, 60);
  [aPath moveToPoint:initial];

  CGPoint point = CGPointMake(290, 60);
  CGPoint centerPoint = CGPointMake(point.x/2, -10);

  [aPath addQuadCurveToPoint:point controlPoint:centerPoint];


  secondPoint = CGPathGetCurrentPoint(aPath.CGPath);

  [aPath addLineToPoint:CGPointMake(secondPoint.x, 200.0)];

  point1 = CGPathGetCurrentPoint(aPath.CGPath);

  CGPoint p = CGPointMake(initial.x,point1.y);
  CGPoint cp = CGPointMake(point1.x/2 ,point1.y/2 + 30);

  [aPath addQuadCurveToPoint:p controlPoint:cp];

 [aPath addLineToPoint:CGPointMake(initial.x, secondPoint.y)];
 [aPath closePath];

 [aPath stroke];

 CAShapeLayer *maskLayer = [CAShapeLayer layer];
 maskLayer.frame = imgView.bounds;
 maskLayer.path = aPath.CGPath;
 imgView.layer.mask = maskLayer;
}
0

OpenGL - . CALayer. , .

- ?

0

All Articles