Commit 239f3246 authored by toby's avatar toby

awesome hold bg animation

parent ed4a5637
......@@ -33,7 +33,8 @@ func randomColor() -> UIColor {
}
func randomTransition() -> BGTransition {
let duration = Double((arc4random() % 5) + 3)
// let duration = Double((arc4random() % 5) + 5)
let duration = 5.0
var start = randomColor()
var end = randomColor()
return BGTransition(duration: duration, startColor: start, endColor: end)
......@@ -46,10 +47,14 @@ class ViewController: UIViewController {
var backgroundTransition: BGTransition!
var paused = false
var animating = false
override func viewDidLoad() {
super.viewDidLoad()
backgroundTransition = randomTransition()
// backgroundTransition = BGTransition(duration: 5.0, startColor: UIColor.blackColor(), endColor: UIColor.whiteColor())
view.backgroundColor = backgroundTransition.startColor
let barrier = UIView(frame: CGRectFromOrigin(view, 0, 40, 130, 20))
......@@ -83,22 +88,70 @@ class ViewController: UIViewController {
switch hold.state {
case UIGestureRecognizerState.Began:
println("started bro")
UIView.animateWithDuration(
self.backgroundTransition.duration,
delay: 0.0,
options: UIViewAnimationOptions.CurveEaseOut,
animations: {
self.view!.backgroundColor = self.backgroundTransition.endColor
},
completion: {
(finished: Bool) -> Void in
println("done animating bro")
})
self.animating = true
if(!paused) {
println("not paused")
UIView.animateWithDuration(
self.backgroundTransition.duration,
delay: 0.0,
options: UIViewAnimationOptions.CurveEaseOut | UIViewAnimationOptions.AllowUserInteraction,
animations: {
self.view!.backgroundColor = self.backgroundTransition.endColor
},
completion: {
(finished: Bool) -> Void in
println("done animating bro")
self.paused = false
self.animating = false
UIView.animateWithDuration(
0.25,
delay: 0.0,
options: UIViewAnimationOptions.CurveEaseInOut | UIViewAnimationOptions.AllowUserInteraction,
animations: {
self.view!.backgroundColor = UIColor.whiteColor()
},
completion: {
(finished: Bool) -> Void in
UIView.animateWithDuration(
0.25,
delay: 0.0,
options: UIViewAnimationOptions.CurveEaseInOut | UIViewAnimationOptions.AllowUserInteraction,
animations: {
self.view!.backgroundColor = self.backgroundTransition.startColor
},
completion: nil)
}
)
})
} else {
println("paused")
paused = false
let pausedTime = self.view!.layer.timeOffset
self.view!.layer.speed = 1
self.view!.layer.timeOffset = 0.0
self.view!.layer.beginTime = 0.0
let timeSincePause = self.view!.layer.convertTime(CACurrentMediaTime(), fromLayer: nil) - pausedTime
self.view!.layer.beginTime = timeSincePause
}
case UIGestureRecognizerState.Ended:
println("ended bro")
println("ended bro \(self.view!.layer.convertTime(CACurrentMediaTime(), fromLayer: nil))")
if(animating == true) {
paused = true
animating = false
let pausedTime = self.view!.layer.convertTime(CACurrentMediaTime(), fromLayer: nil)
self.view!.layer.speed = 0
self.view!.layer.timeOffset = pausedTime
}
default:
println("fuck you bro" )
// println("fuck you bro" )
()
}
}
......
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