0

UIView アニメーションを使用して、ボタンを高くしたり短くしたりする簡単なアニメーション コードを書いています。コードは少し長いですが、かなり単純です。

func animateButton(aButton: UIButton, step: Int)
{
  let localStep = step - 1

  let localButton = aButton
  let halfHeight = aButton.bounds.height / 2

  var transform: CGAffineTransform
  switch step
  {
  case 2:
    //Make the center of the grow animation be the bottom center of the button
    transform = CGAffineTransformMakeTranslation(0, -halfHeight)

    //Animate the button to 120% of it's normal height.
    transform = CGAffineTransformScale( transform, 1.0, 1.2)
    transform = CGAffineTransformTranslate( transform, 0, halfHeight)
    UIView.animateWithDuration(0.5, animations:
      {
        aButton.transform = transform
      },
      completion:
      {
        (finshed) in
        //------------------------------------
        //--- This line throws the error ---
        animateButton(aButton, step: 1)
        //------------------------------------
    })
  case 1:
    //In the second step, shrink the height down to .25 of normal
    transform = CGAffineTransformMakeTranslation(0, -halfHeight)

    //Animate the button to 120% of it's normal height.
    transform = CGAffineTransformScale( transform, 1.0, 0.25)
    transform = CGAffineTransformTranslate( transform, 0, halfHeight)
    UIView.animateWithDuration(0.5, animations:
      {
        aButton.transform = transform
      },
      completion:
      {
        (finshed) in
        animateButton(aButton, step: 0)
    })
  case 0:
    //in the final step, animate the button back to full height.
    UIView.animateWithDuration(0.5)
      {
        aButton.transform = CGAffineTransformIdentity
    }
  default:
    break
  }
}

アニメーション メソッドの完了ブロックはクロージャです。animateButton「クロージャのメソッドへの呼び出しにはself.、キャプチャ セマンティクスを明示的にするために明示的なものが必要です。

問題は、パラメータ aButton が囲んでいる関数のパラメータです。インスタンス変数への参照はありません。

これはコンパイラのバグのようです。ここで何か不足していますか?

4

1 に答える 1