Skip to content

Instantly share code, notes, and snippets.

@joncardasis
Created May 31, 2017 20:07
Show Gist options
  • Select an option

  • Save joncardasis/d5e1d7296e89419ae976da2464fa1e67 to your computer and use it in GitHub Desktop.

Select an option

Save joncardasis/d5e1d7296e89419ae976da2464fa1e67 to your computer and use it in GitHub Desktop.
[Medium Gists] Complex Transaction
let oldValue = styledButton.frame.width/2
let newButtonWidth: CGFloat = 60
/* Do Animations */
CATransaction.begin()
CATransaction.setAnimationDuration(2.0)
CATransaction.setAnimationTimingFunction(CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut))
// View animations
UIView.animate(withDuration: 2.0) {
self.styledButton.frame = CGRect(x: 0, y: 0, width: newButtonWidth, height: newButtonWidth)
self.styledButton.center = self.view.center
}
// Layer animations
let cornerAnimation = CABasicAnimation(keyPath: #keyPath(CALayer.cornerRadius))
cornerAnimation.fromValue = oldValue
cornerAnimation.toValue = newButtonWidth/2
styledButton.layer.cornerRadius = newButtonWidth/2
styledButton.layer.add(cornerAnimation, forKey: #keyPath(CALayer.cornerRadius))
CATransaction.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment