Macaw iOS-点击时设置动画或反转

Macaw iOS-点击时设置动画或反转,ios,swift,animation,Ios,Swift,Animation,我只是被困在金刚鹦鹉图书馆里,试着做一些简单的点击事件动画 我有一个简单的动画,如果你点击一个节点,它会动画到一个新节点。现在,当你再次点击时,我想反转动画。但是,反向动画似乎没有启动 class button: MacawView { var animation:Animation? var reverse:Bool = false required convenience init?(coder aDecoder: NSCoder) { let stroke = Str

我只是被困在金刚鹦鹉图书馆里,试着做一些简单的点击事件动画

我有一个简单的动画,如果你点击一个节点,它会动画到一个新节点。现在,当你再次点击时,我想反转动画。但是,反向动画似乎没有启动

class button: MacawView {
  var animation:Animation?
  var reverse:Bool = false

  required convenience init?(coder aDecoder: NSCoder) {
    let stroke = Stroke(width: 15.0, cap: .round)

    let contents1 = [
        Shape(form: Line(x1: 150.0, y1: 150.0, x2: 175.0, y2: 125.0), stroke: stroke),
        Shape(form: Line(x1: 150.0, y1: 150.0, x2: 225.0, y2: 150.0), stroke: stroke),
        Shape(form: Line( x1: 150.0, y1: 150.0, x2: 175.0, y2: 175.0), stroke: stroke),
        ]

    let contents2 = [
        Shape(form: Line(x1: 130.0, y1: 110.0, x2: 245.0, y2: 110.0), stroke: stroke),
        Shape(form: Line(x1: 130.0, y1: 150.0, x2: 245.0, y2: 150.0), stroke: stroke),
        Shape(form: Line(x1: 130.0, y1: 190.0, x2: 245.0, y2: 190.0), stroke: stroke),
        ]

    let group = contents1.group()

    self.init(node: group, coder: aDecoder)
    animation = group.contentsVar.animation(to: contents2)
    group.onTap { (tapEvent) in
        if(!self.reverse) {
            self.animation?.play()
        } else {
            _ = self.animation?.reverse().play()
        }
        self.reverse = !self.reverse
    }
  }
}
我有一种感觉,那是因为我不太了解金刚鹦鹉群体和内容的生命周期。这或者是回调中的范围问题。 当我想要它反转时,回调会被再次调用,并进入反转行,只是看起来什么都没有发生


有人有什么想法吗?

原来在金刚鹦鹉的造型中没有reverse()方法。 这个请求修复了这个问题 欢迎您查看