Created
October 31, 2016 14:27
-
-
Save Eluss/ecbc2a8c3d20724d2b1275ac71699680 to your computer and use it in GitHub Desktop.
This file contains 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
var buttonLeftConstraint: NSLayoutConstraint? | |
func pureLayout() { | |
buttonLeftConstraint = animateButton.autoPinEdge(toSuperviewEdge: .left, withInset: 20) | |
animateButton.autoPinEdge(toSuperviewEdge: .top, withInset: 50) | |
animateButton.autoSetDimensions(to: CGSize(width: 100, height: 100)) | |
} | |
func animate() { | |
UIView.animate(withDuration: 1) { | |
let random: Double = Double(arc4random_uniform(200)) | |
self.buttonLeftConstraint?.constant = random | |
self.view.layoutIfNeeded() | |
} | |
} | |
/// | |
var buttonLeftConstraint: Constraint? | |
func snapKit() { | |
animateButton.snp.makeConstraints { (make) in | |
buttonLeftConstraint = make.left.equalTo(self.view).offset(20).constraint | |
make.top.equalTo(self.view).inset(50) | |
make.size.equalTo(CGSize(width: 100, height: 100)) | |
} | |
} | |
func animate() { | |
UIView.animate(withDuration: 1) { | |
let random: Double = Double(arc4random_uniform(200)) | |
self.buttonLeftConstraint?.update(offset: random) | |
self.view.layoutIfNeeded() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment