LoginSignup
6
6

More than 5 years have passed since last update.

SwiftでFacebook popのPOPSpringAnimationを行う

Last updated at Posted at 2014-12-07

POPSpringAnimationをやってみる

fbpop2gif.gif

四角形がバウンドしながら大きくなるアニメーション(POPSpringAnimation)を作ってみます。

PopをSwiftで使用する

「ProjectName-Bridging-Header.h」というヘッダファイルを作成し、以下を記述します。

#import <POP/POP.h>

・参考
Swift内でObjective-Cで定義したクラスを利用する

アニメーション作成

Viewを作成

// myViewを生成.
myView = UIView(frame: CGRectMake(0, 0, 10, 10))
myView.backgroundColor = UIColor.orangeColor()
myView.layer.position = CGPointMake(self.view.frame.width/2, self.view.frame.height/2)

self.view.addSubview(myView)

アニメーションを定義

func scaleView(view: UIView) {
    let anime = POPSpringAnimation()

    anime.property = POPAnimatableProperty.propertyWithName(kPOPLayerSize) as POPAnimatableProperty
    anime.springBounciness = 12.0
    anime.springSpeed = 10.0    

    anime.toValue = NSValue(CGSize:CGSizeMake(300, 300))
    view.pop_addAnimation(anime, forKey: "bound")
}

実行

scaleView(myView)

・参考
https://github.com/facebook/pop
http://stackoverflow.com/questions/24150240/swift-nsvalue-valuewithcgrect

6
6
0

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
6
6