【问题标题】:How can i create curve UIView/UIImageView not with animation?如何不使用动画创建曲线 UIView/UIImageView?
【发布时间】:2015-01-30 10:04:26
【问题描述】:

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

【问题讨论】:

  • 我认为你不能使用 Quartz 或 UIKit。当然,您可以使用贝塞尔路径构建弯曲路径,但它们仅适用于已绘制的内容,而不适用于子视图或子图层。使用石英和 CATransform3D,您可以实现某种 3d 透视图。
    您要做的是 OpenGL 任务。
  • 没有open gl是不是不可能?
  • 使用具有一定透明度的图像视图有什么问题?

标签: ios objective-c uiview


【解决方案1】:

根据我的水平和理解,我已经完成了一些可能对您有帮助的编码.. 如果不是请忽略它..

第一次从新文件创建自定义视图

接下来,我们需要将 ViewController 的视图属性的类从 UIView 更改为我们的 CustomView 类。打开 MainStoryboard.storyboard 并在文档大纲中单击查看图标。然后,打开身份检查器(option+command+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;
}

【讨论】:

  • 不,它不工作只是在 imageview 上画一条曲线。并掩盖它。谢谢回复
【解决方案2】:

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

也许用图像和一些旋转视图或其他东西来伪造它?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多