【问题标题】:Change CAShapeLayer stroke position更改 CAShapeLayer 笔划位置
【发布时间】:2018-10-19 22:56:35
【问题描述】:

我有一个collectionviewcell cell,我正在添加一个CAShapeLayer 给我的frontImageView 一个半边框。我现在成功创建的代码创建了一个半边框,但不是我想要的。设置stokeEnd=0.5 在我的imageView 底部创建一个半边框。我希望边框位于 imageView 的右侧。从顶部中心到底部中心(右侧)。

我可以沿着右侧从 imageView 的顶部中心到底部中心绘制笔划线吗?

CAShapeLayer *shape = [CAShapeLayer layer];
UIBezierPath *path=[UIBezierPath bezierPathWithOvalInRect:cell.frontImageView.frame];
[shape setPath:path.CGPath];

shape.strokeColor=[UIColor purpleColor].CGColor;
shape.fillColor=[UIColor clearColor].CGColor;
shape.lineWidth = 5.0f;
shape.lineCap = kCALineCapRound;
[shape setStrokeEnd:0.5];
[cell.layer addSublayer:shape];

【问题讨论】:

  • 这很容易。添加变换以旋转形状图层。

标签: ios objective-c cashapelayer


【解决方案1】:

您可以使用一般弧形路径创建路径:(Swift 4.2)

UIBezierPath(arcCenter: view.center, radius: view.frame.width / 2, startAngle: -CGFloat.pi / 2.0, endAngle: CGFloat.pi / 2.0, clockwise: true)

通过此路径设置形状的路径。

【讨论】:

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