Skip to content

Instantly share code, notes, and snippets.

@rubenroques
Created February 11, 2016 11:53
Show Gist options
  • Save rubenroques/a19bafb930d05b88c38c to your computer and use it in GitHub Desktop.
Save rubenroques/a19bafb930d05b88c38c to your computer and use it in GitHub Desktop.
class LiveView: UIView {
var startButton : UIButton
var resetButton : UIButton
var circle1 : UIView
var circle2 : UIView
var circle3 : UIView
override init(frame: CGRect) {
startButton = UIButton(type: UIButtonType.System)
startButton.frame = CGRect(x: 40, y: 600, width: 50, height: 30)
startButton.setTitle("Start", forState: UIControlState.Normal)
resetButton = UIButton(type: UIButtonType.System)
resetButton.frame = CGRect(x: 110, y: 600, width: 50, height: 30)
resetButton.setTitle("Reset", forState: UIControlState.Normal)
circle1 = UIView(frame: CGRect(x: 50.0, y: 400.0, width: 100.0, height: 100.0))
circle1.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.1)
circle1.layer.borderWidth = 4
circle1.layer.borderColor = UIColor.lightGrayColor().CGColor
circle1.alpha = 0
circle1.layer.cornerRadius = 50.0
circle2 = UIView(frame: CGRect(x: 200.0, y: 400.0, width: 100.0, height: 100.0))
circle2.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.1)
circle2.layer.borderWidth = 4
circle2.layer.borderColor = UIColor.lightGrayColor().CGColor
circle2.alpha = 0
circle2.layer.cornerRadius = 50.0
circle3 = UIView(frame: CGRect(x: 350.0, y: 400.0, width: 100.0, height: 100.0))
circle3.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.1)
circle3.layer.borderWidth = 4
circle3.layer.borderColor = UIColor.lightGrayColor().CGColor
circle3.alpha = 0
circle3.layer.cornerRadius = 50.0
super.init(frame: frame)
self.backgroundColor = UIColor.whiteColor()
self.addSubview(startButton)
self.addSubview(resetButton)
self.addSubview(circle1)
self.addSubview(circle2)
self.addSubview(circle3)
startButton.addTarget(self, action: Selector("start"), forControlEvents: UIControlEvents.TouchUpInside)
resetButton.addTarget(self, action: Selector("reset"), forControlEvents: UIControlEvents.TouchUpInside)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func start() {
let springV : CGFloat = 0.1
let damp : CGFloat = 0.46
let duration : NSTimeInterval = 0.72
UIView.animateWithDuration(duration, delay: 0.0, usingSpringWithDamping: damp, initialSpringVelocity: springV, options: [], animations: {
self.circle1.alpha = 1
self.circle1.center = CGPoint(x: self.circle1.center.x, y: 200)
}, completion: nil)
UIView.animateWithDuration(duration, delay: 0.11, usingSpringWithDamping: damp, initialSpringVelocity: springV, options: [], animations: {
self.circle2.alpha = 1
self.circle2.center = CGPoint(x: self.circle2.center.x, y: 200)
}, completion: nil)
UIView.animateWithDuration(duration, delay: 0.22, usingSpringWithDamping: damp, initialSpringVelocity: springV, options: [], animations: {
self.circle3.alpha = 1
self.circle3.center = CGPoint(x: self.circle3.center.x, y: 200)
}, completion: nil)
}
func reset() {
print("pressed r")
circle1.alpha = 0
circle1.center = CGPoint(x: circle1.center.x, y: 400)
circle2.alpha = 0
circle2.center = CGPoint(x: circle2.center.x, y: 400)
circle3.alpha = 0
circle3.center = CGPoint(x: circle3.center.x, y: 400)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment