Created
November 6, 2018 18:53
-
-
Save vialyx/d0d29dba72ca8dabb36ca514e3874e22 to your computer and use it in GitHub Desktop.
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
@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)") | |
} | |
} else { | |
// Start Repeat Animation for UILabel | |
UIView.animate(withDuration: 0.5, | |
delay: 0.0, | |
// .repeat option create loop for that animation | |
options: [.repeat, .autoreverse], | |
animations: { | |
// Concat static text with text from UITextField | |
self.label.text = "Entered name: " + (self.field.text ?? "") | |
// Make offset from UILabel frame | |
self.label.frame = self.label.frame.offsetBy(dx: 100, dy: 0) | |
}) { (finish) in | |
print("\(String(describing: self.label)) animation finish: \(finish)") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment