Commit d356aadc authored by toby's avatar toby

pause unpause

parent df8f7a6e
......@@ -8,6 +8,23 @@
import UIKit
extension UIView {
func pause() -> Void {
let pausedTime = self.layer.convertTime(CACurrentMediaTime(), fromLayer: nil)
self.layer.speed = 0
self.layer.timeOffset = pausedTime
}
func unpause() -> Void {
let pausedTime = self.layer.timeOffset
self.layer.speed = 1
self.layer.timeOffset = 0.0
self.layer.beginTime = 0.0
let timeSincePause = self.layer.convertTime(CACurrentMediaTime(), fromLayer: nil) - pausedTime
self.layer.beginTime = timeSincePause
}
}
func degreesToRadians(degrees: CGFloat) -> CGFloat {
return degrees * (3.1415926 / 180)
}
......
......@@ -114,11 +114,7 @@ class ViewController: UIViewController {
} else {
println("paused")
self.appState.paused = false
let pausedTime = self.view!.layer.timeOffset
self.view!.layer.speed = 1
self.view!.layer.timeOffset = 0.0
let timeSincePause = self.view!.layer.convertTime(CACurrentMediaTime(), fromLayer: nil) - pausedTime
self.view!.layer.beginTime = timeSincePause
self.view.unpause()
}
case UIGestureRecognizerState.Ended:
......@@ -126,9 +122,7 @@ class ViewController: UIViewController {
if(self.appState.animating == true) {
self.appState.paused = true
self.appState.animating = false
let pausedTime = self.view!.layer.convertTime(CACurrentMediaTime(), fromLayer: nil)
self.view!.layer.speed = 0
self.view!.layer.timeOffset = pausedTime
self.view.pause()
}
default:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment