LoginSignup
1
2

More than 5 years have passed since last update.

ホームアプリアイコンの削除時にプルプル震えるアニメーション

Last updated at Posted at 2017-07-19

下記のアニメーションの処理は現在では古い方法となっております。一応残してはおきますが、もし参考にする時はお気をつけください。

ちょっと適当になんでも良いからプログラムを作りたくなり、
iphoneのホームボタンの様にプルプル震えるアニメーションを簡単に使用できる
UIButtonクラスを継承したクラスを作成してみた

    UIView.beginAnimations(nil, context: nil)
    UIView.setAnimationDuration(TimeInterval(self.animSpeed))
    UIView.setAnimationDelay(0.0)
    UIView.setAnimationRepeatCount(1e100)

    if (self.type == .right) {
        let rote : CGAffineTransform = CGAffineTransform(rotationAngle: CGFloat(self.slopeRigt * (.pi / 180.0)));
        self.transform = rote
        self.type = .left;
    } else {
        let rote : CGAffineTransform = CGAffineTransform(rotationAngle: CGFloat(self.slopeLeft * (.pi / 180.0)));
        self.transform = rote
        self.type = .right
    }

    UIView.commitAnimations()

こんな感じで,CGAffineTransformを使用して
右と左にプルプル震える様にアニメーションをさせてあげる

終了するときは
self.layer.removeAllAnimations();
これで終了

一つ気になったのが、
無限にアニメーションさせるために
setAnimationRepeatCountを使用しているが、その時の値が1e100であること、、、
ちょっと調べたらこれで無限アニメーションになるよって記事みつけたけど、本当にいいのだろうか、、、

ってか、このアニメーションのさせ方自体が古い?
アニメーションのクロージャを設定するやり方が今時のやり方かな?

時間がある時にまた違う方法で実装してみようかな

1
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2