Commit 356e4fab by Daniel Dahan

updated animation for TextField

parent 320848c4
...@@ -53,14 +53,18 @@ class ViewController: UIViewController, TextFieldDelegate { ...@@ -53,14 +53,18 @@ class ViewController: UIViewController, TextFieldDelegate {
/// Prepares the name TextField. /// Prepares the name TextField.
private func prepareNameField() { private func prepareNameField() {
let textField: TextField = TextField(frame: CGRectMake(57, 100, 300, 24)) let w: CGFloat = 300
let x: CGFloat = (MaterialDevice.width - w) / 2
let textField: TextField = TextField(frame: CGRectMake(x, 100, w, 24))
textField.placeholder = "First Name" textField.placeholder = "First Name"
view.addSubview(textField) view.addSubview(textField)
} }
/// Prepares the email TextField. /// Prepares the email TextField.
private func prepareEmailField() { private func prepareEmailField() {
let textField: TextField = TextField(frame: CGRectMake(57, 200, 300, 24)) let w: CGFloat = 300
let x: CGFloat = (MaterialDevice.width - w) / 2
let textField: TextField = TextField(frame: CGRectMake(x, 200, w, 24))
textField.delegate = self textField.delegate = self
textField.placeholder = "Email" textField.placeholder = "Email"
...@@ -70,7 +74,7 @@ class ViewController: UIViewController, TextFieldDelegate { ...@@ -70,7 +74,7 @@ class ViewController: UIViewController, TextFieldDelegate {
*/ */
textField.detailLabel = UILabel() textField.detailLabel = UILabel()
textField.detailLabel!.text = "Email is incorrect." textField.detailLabel!.text = "Email is incorrect."
textField.detailLabel!.font = RobotoFont.mediumWithSize(12) textField.detailLabel!.font = RobotoFont.regularWithSize(12)
textField.detailLabelActiveColor = MaterialColor.red.accent3 textField.detailLabelActiveColor = MaterialColor.red.accent3
// textField.detailLabelAutoHideEnabled = false // Uncomment this line to have manual hiding. // textField.detailLabelAutoHideEnabled = false // Uncomment this line to have manual hiding.
......
...@@ -70,7 +70,7 @@ class ViewController: UIViewController, TextFieldDelegate { ...@@ -70,7 +70,7 @@ class ViewController: UIViewController, TextFieldDelegate {
*/ */
emailField.detailLabel = UILabel() emailField.detailLabel = UILabel()
emailField.detailLabel!.text = "Email is incorrect." emailField.detailLabel!.text = "Email is incorrect."
emailField.detailLabel!.font = RobotoFont.mediumWithSize(12) emailField.detailLabel!.font = RobotoFont.regularWithSize(12)
emailField.detailLabelActiveColor = MaterialColor.red.accent3 emailField.detailLabelActiveColor = MaterialColor.red.accent3
// emailField.detailLabelAutoHideEnabled = false // Uncomment this line to have manual hiding. // emailField.detailLabelAutoHideEnabled = false // Uncomment this line to have manual hiding.
} }
......
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'Material' s.name = 'Material'
s.version = '1.39.3' s.version = '1.39.4'
s.license = 'BSD' s.license = 'BSD'
s.summary = 'Express your creativity with Material, an animation and graphics framework for Google\'s Material Design and Apple\'s Flat UI in Swift.' s.summary = 'Express your creativity with Material, an animation and graphics framework for Google\'s Material Design and Apple\'s Flat UI in Swift.'
s.homepage = 'http://cosmicmind.io' s.homepage = 'http://cosmicmind.io'
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>FMWK</string> <string>FMWK</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.39.3</string> <string>1.39.4</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
......
...@@ -557,10 +557,11 @@ public class TextField : UITextField { ...@@ -557,10 +557,11 @@ public class TextField : UITextField {
titleLabel = UILabel() titleLabel = UILabel()
titleLabel.hidden = true titleLabel.hidden = true
titleLabel.font = RobotoFont.mediumWithSize(12) titleLabel.font = RobotoFont.mediumWithSize(12)
addSubview(titleLabel)
titleLabelColor = MaterialColor.grey.base titleLabelColor = MaterialColor.grey.base
titleLabelActiveColor = MaterialColor.blue.accent3 titleLabelActiveColor = MaterialColor.blue.accent3
addSubview(titleLabel)
if 0 < text?.utf16.count { if 0 < text?.utf16.count {
showTitleLabel() showTitleLabel()
} else { } else {
...@@ -632,7 +633,7 @@ public class TextField : UITextField { ...@@ -632,7 +633,7 @@ public class TextField : UITextField {
titleLabel.hidden = false titleLabel.hidden = false
UIView.animateWithDuration(0.15, animations: { [unowned self] in UIView.animateWithDuration(0.15, animations: { [unowned self] in
self.titleLabel.alpha = 1 self.titleLabel.alpha = 1
self.titleLabel.font = self.font?.fontWithSize(12) self.titleLabel.transform = CGAffineTransformScale(self.titleLabel.transform, 0.75, 0.75)
self.titleLabel.frame = CGRectMake(0, -(self.titleLabelAnimationDistance + h), self.bounds.width, h) self.titleLabel.frame = CGRectMake(0, -(self.titleLabelAnimationDistance + h), self.bounds.width, h)
}) })
} }
...@@ -640,15 +641,12 @@ public class TextField : UITextField { ...@@ -640,15 +641,12 @@ public class TextField : UITextField {
/// Hides and animates the titleLabel property. /// Hides and animates the titleLabel property.
private func hideTitleLabel() { private func hideTitleLabel() {
UIView.animateWithDuration(0.1, animations: { [unowned self] in UIView.animateWithDuration(0.15, animations: { [unowned self] in
self.titleLabel.transform = CGAffineTransformIdentity
self.titleLabel.frame = self.bounds self.titleLabel.frame = self.bounds
}) { [unowned self] _ in }) { [unowned self] _ in
UIView.animateWithDuration(0.15, animations: { [unowned self] in self.placeholder = self.placeholderText
self.titleLabel.font = self.font self.titleLabel.hidden = true
}) { [unowned self] _ in
self.placeholder = self.placeholderText
self.titleLabel.hidden = true
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment