2

我想在 Swift 中实现 UIPushBehavior,但我总是遇到以下错误:...查看项目 UIImageView 应该是 UIDynamicAnimator 中参考视图的后代...

我正在将视图添加到行为中,并将行为添加到动画师...

@IBAction func push(sender: UITapGestureRecognizer) {

    let pushBehavior = UIPushBehavior(items: [aView], mode: .Instantaneous)
    pushBehavior.magnitude = 0.5
    pushBehavior.action = { [unowned pushBehavior] in
        pushBehavior.dynamicAnimator!.removeBehavior(pushBehavior)
    }
    animator.addBehavior(pushBehavior)

}

我还将动画师的referenceView设置为应该发生动作的gameView......

private lazy var animator : UIDynamicAnimator = {

   let lazilyCreatedDynamicAnimator = UIDynamicAnimator(referenceView:self.gameView)
   return lazilyCreatedDynamicAnimator

}()

我希望你能帮助我弄清楚如何解决我的小问题......

4

0 回答 0