Skip to content

Instantly share code, notes, and snippets.

@saru2020
Last active October 17, 2019 15:10
Show Gist options
  • Save saru2020/76ab948d508d20a2ccbe7cdcfd634157 to your computer and use it in GitHub Desktop.
Save saru2020/76ab948d508d20a2ccbe7cdcfd634157 to your computer and use it in GitHub Desktop.
let oldValue = button.frame.width/2
let newButtonWidth: CGFloat = 60
/* Do Animations */
CATransaction.begin() //1
CATransaction.setAnimationDuration(2.0) //2
CATransaction.setAnimationTimingFunction(CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)) //3
// View animations //4
UIView.animate(withDuration: 1.0) {
self.button.frame = CGRect(x: 0, y: 0, width: newButtonWidth, height: newButtonWidth)
self.button.center = self.view.center
}
// Layer animations
let cornerAnimation = CABasicAnimation(keyPath: #keyPath(CALayer.cornerRadius)) //5
cornerAnimation.fromValue = oldValue //6
cornerAnimation.toValue = newButtonWidth/2 //7
button.layer.cornerRadius = newButtonWidth/2 //8
button.layer.add(cornerAnimation, forKey: #keyPath(CALayer.cornerRadius)) //9
CATransaction.commit() //10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment