Skip to content

Instantly share code, notes, and snippets.

@RayPS
Last active July 2, 2016 21:46
Show Gist options
  • Save RayPS/219af464815421000e77dddca190e3a2 to your computer and use it in GitHub Desktop.
Save RayPS/219af464815421000e77dddca190e3a2 to your computer and use it in GitHub Desktop.
UIButton Extension
import UIKit
import Spring
var _scaleFactor: CGFloat = 1
public extension SpringButton {
@nonobjc static let scaleTo = "_scaleTo"
@nonobjc static let scaleBack = "_scaleBack"
public func addTargetForAnimation(scaleFactor: CGFloat?) {
_scaleFactor = scaleFactor!
addTarget(self, action: Selector(SpringButton.scaleTo), forControlEvents: .TouchDown)
addTarget(self, action: Selector(SpringButton.scaleBack), forControlEvents: .TouchUpInside)
addTarget(self, action: Selector(SpringButton.scaleBack), forControlEvents: .TouchDragExit)
}
func _scaleTo() {
self.scaleX = _scaleFactor
self.scaleY = _scaleFactor
self.animateTo()
}
func _scaleBack() {
self.scaleX = 1
self.scaleY = 1
self.animateTo()
}
}
import UIKit
var _scaleFactor: CGFloat = 1
public extension UIButton {
@nonobjc static let scaleTo = "_scaleTo"
@nonobjc static let scaleBack = "_scaleBack"
public func addTargetForAnimation(scaleFactor: CGFloat?) {
_scaleFactor = scaleFactor!
addTarget(self, action: Selector(UIButton.scaleTo), forControlEvents: .TouchDown)
addTarget(self, action: Selector(UIButton.scaleBack), forControlEvents: .TouchUpInside)
addTarget(self, action: Selector(UIButton.scaleBack), forControlEvents: .TouchDragExit)
}
func _scaleTo() {
UIView.animateWithDuration(0.1) {
self.transform = CGAffineTransformMakeScale(_scaleFactor, _scaleFactor)
}
}
func _scaleBack() {
UIView.animateWithDuration(0.1) {
self.transform = CGAffineTransformIdentity
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment