POPSpringAnimationをやってみる
四角形がバウンドしながら大きくなるアニメーション(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