Skip to content

Instantly share code, notes, and snippets.

@vialyx
Created November 6, 2018 18:38
Show Gist options
  • Save vialyx/e387c8e8c8726cd8a492d25035602c94 to your computer and use it in GitHub Desktop.
Save vialyx/e387c8e8c8726cd8a492d25035602c94 to your computer and use it in GitHub Desktop.
// MARK: - Actions
@IBAction func buttonDidTap(_ sender: Any) {
// Check text in field. Animation is starting only if text is empty
if field.text?.isEmpty ?? true {
UIView.animate(withDuration: 0.3,
delay: 0.0,
// Look options list here https://developer.apple.com/documentation/uikit/uiviewanimationoptions
options: [.autoreverse],
animations: {
// Create CGAffineTransform with 5 degree (CG works with radians) and convert in to radians
self.field.transform = CGAffineTransform(rotationAngle: CGFloat(5).degreesToRadians)
// Add scale factor to the created transform
.scaledBy(x: 1.2, y: 1.2)
}) { (finish) in
// Clear transform .identity is a empty transform
self.field.transform = .identity
print("\(String(describing: self.field)) animation finish: \(finish)")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment