如何创建不用动画的曲线UIView / UIImageView?

时间:2014-12-02 08:14:20

标签: ios objective-c uiview

我如何创建一个看起来像这样的uiview,并且它的子视图也能获得相同的效果。 在网上搜索后我发现它可以由CALayer完成,但我对此没有足够的了解。请帮我。提前谢谢。

How

2 个答案:

答案 0 :(得分:0)

根据我的水平和我的理解,我做了一些可能对你有帮助的编码。 如果没有,请忽略它..

1st从新文件创建自定义视图

接下来,我们需要将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;
}

答案 1 :(得分:0)

没有OpenGL或其他引擎就不会发生。你不能用这种方式变形CALayer。层的基本思想是它是一个平面。

可能用图像和一些旋转的视图或其他东西伪造它?