代码之家  ›  专栏  ›  技术社区  ›  Loanb222 user2746752

如何用swift旋转线条

  •  -1
  • Loanb222 user2746752  · 技术社区  · 9 年前

    我用Core Graphics创建了一条线,我想移动线的端点,使第一个点保持不变,另一个点向下移动。这是我用来创建线条的代码:

    let context = UIGraphicsGetCurrentContext()
    CGContextSetLineWidth(context, 2.0)
    let colorSpace = CGColorSpaceCreateDeviceRGB()
    let components: [CGFloat] = [0.0, 0.0, 1.0, 1.0]
    let color = CGColorCreate(colorSpace, components)
    CGContextSetStrokeColorWithColor(context, color)
    CGContextMoveToPoint(context, 30, 90)
    CGContextAddLineToPoint(context, 300, 30)
    CGContextStrokePath(context)
    
    1 回复  |  直到 9 年前
        1
  •  0
  •   Community Mohan Dere    9 年前

    设置动画 绘画 您可以使用CAShapeLayer并更改其路径,而不是该图形的容器(视图或层);这是一个可动画化的变化。如果该动画没有提供您想要的内容,并且或多或少不可能对其进行精细控制,则必须使用自定义动画属性,如中所示 this answer 属于我的。