【问题标题】:Animate roundedrect with CoreAnimation使用 CoreAnimation 对圆角矩形进行动画处理
【发布时间】:2017-01-03 19:28:28
【问题描述】:

伙计们,我有以下代码来生成贝塞尔路径

firstLine.path = UIBezierPath(roundedRect: CGRect(x: frameSize.width / 2.2, y: frameSize.height / 2.6, width: 4, height: 4), cornerRadius: 10).cgPath

我尝试通过将 firstLine 移动到屏幕右侧 x 值并返回到原始位置来为 firstLine 设置动画。但我不知道动画中的 keyPath 用什么。

let animation = CABasicAnimation(keyPath: "??")
animation.toValue = // this should be the position to move?
animation.duration = 0.5 // duration of the animation
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut) // animation curve is Ease Out
animation.fillMode = kCAFillModeBoth // keep to value after finishing
animation.isRemovedOnCompletion = false // don't remove after finishing
animation.autoreverses = true
animation.repeatCount = HUGE

有人可以帮我解决这个问题吗:)

【问题讨论】:

    标签: swift swift3 core-animation uibezierpath


    【解决方案1】:

    发件人:https://developer.apple.com/reference/quartzcore/cabasicanimation

    您使用继承的 init(keyPath:) 方法创建 CABasicAnimation 的实例,指定要在渲染树中进行动画处理的属性的键路径。

    您想要的示例:

    let animation = CABasicAnimation(keyPath: "position")
    animation.fromValue = [startX, startY]
    animation.toValue = [destinationX, destinationY]
    

    【讨论】:

    • 位置键路径在某种程度上不适用于 bezierpath。
    • @Reshad 你能添加你用来移动贝塞尔路径的代码吗?
    猜你喜欢
    • 1970-01-01
    • 2010-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多