こちらのブログにある通り、WatchKit向けのアニメーションを作成するのは現状極めて面倒と言わざるを得ません。
http://d.hatena.ne.jp/shu223/20150214/1423901142
そこでiOS側でUIViewを今までどおりレンダリングして、その結果をファイルにしたりUIImageにしてWatchKitに渡せばいいじゃない!というライブラリを書いてみたので公開いたします。
https://github.com/akisute/ParaMangar
このParaMangarを使うとこんな感じでアニメーションが作れます。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Basic example | |
let duration = 1.0 | |
self.animator = ParaMangar.renderViewForDuration(self.targetView, duration: duration, frameInterval: 2).toFile("Sample1", completion: {path in | |
self.animator = nil | |
println("Completed: \(path)") | |
}) | |
// More complex example | |
// Render UIView animations! | |
self.animator = ParaMangar.renderViewForDuration(self.targetView, duration: duration, block: { | |
UIView.animateWithDuration(duration/2, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 2.0, options: UIViewAnimationOptions.allZeros, animations: { () -> Void in | |
self.animatingView.transform = CGAffineTransformMakeScale(2.0, 2.0) | |
}, completion: nil) | |
UIView.animateWithDuration(duration/2, delay: duration/2, usingSpringWithDamping: 0.8, initialSpringVelocity: 2.0, options: UIViewAnimationOptions.allZeros, animations: { () -> Void in | |
self.animatingView.transform = CGAffineTransformIdentity | |
}, completion: nil) | |
}).toImage(duration, completion: { image in | |
self.animator = nil | |
self.imageView.image = image | |
}) |
ライセンスはMITです。
あまりテスト出来ていないのでバグだらけかもしれませんが、ご意見issueなどgithubでお寄せいただければ幸いでございます!!