Created
May 31, 2017 20:07
-
-
Save joncardasis/d5e1d7296e89419ae976da2464fa1e67 to your computer and use it in GitHub Desktop.
[Medium Gists] Complex Transaction
This file contains hidden or 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
| 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