Skip to content

Instantly share code, notes, and snippets.

@darrinhenein
Created March 25, 2015 18:42
Show Gist options
  • Save darrinhenein/ee999eb5e2667b59cdae to your computer and use it in GitHub Desktop.
Save darrinhenein/ee999eb5e2667b59cdae to your computer and use it in GitHub Desktop.
url bar animations
private func updateLayoutForEditing(#editing: Bool) {
self.progressBar.hidden = editing
self.editTextField.hidden = !editing
self.locationContainerConstraints.uninstall()
if editing {
self.locationContainer.snp_updateConstraints { make in
self.locationContainerConstraints = make.leading.equalTo(self).offset(URLBarViewUX.LocationLeftPadding)
make.trailing.equalTo(self.cancelButton.snp_leading)
make.centerY.equalTo(self).offset(StatusBarHeight / 2)
}
} else {
self.locationContainer.snp_updateConstraints { make in
self.locationContainerConstraints = make.leading.equalTo(self).offset(URLBarViewUX.LocationLeftPadding)
make.trailing.equalTo(self.tabsButton.snp_leading).offset(-10)
make.centerY.equalTo(self).offset(StatusBarHeight / 2)
}
}
// show both buttons during transition
self.tabsButton.hidden = false
self.cancelButton.hidden = false
UIView.animateWithDuration(0.4, delay: 0.0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.0, options: nil, animations: { _ in
if editing {
self.cancelButton.alpha = 1
self.cancelButton.transform = CGAffineTransformIdentity
self.tabsButton.transform = CGAffineTransformMakeTranslation(self.tabsButton.frame.width, 0)
} else {
self.cancelButton.alpha = 0
self.tabsButton.transform = CGAffineTransformIdentity
self.cancelButton.transform = CGAffineTransformMakeTranslation(self.cancelButton.frame.width, 0)
}
self.layoutIfNeeded()
}, completion: { _ in
self.tabsButton.hidden = editing
self.cancelButton.hidden = !editing
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment