@@ -132,20 +132,24 @@ public class LTBouncyTextField : UITextField {
132
132
}
133
133
134
134
func _didChange ( notification: NSNotification ) {
135
- if notification. object === self {
136
- if text. lengthOfBytesUsingEncoding ( NSUTF8StringEncoding) > 0 {
137
- if alwaysBouncePlaceholder {
138
-
139
- _animatePlaceholder ( toRight: true )
140
- } else {
141
- lt_placeholderLabel. hidden = true
142
- }
135
+ guard notification. object === self else {
136
+ return
137
+ }
138
+ guard let text = text else {
139
+ return
140
+ }
141
+ if text. lengthOfBytesUsingEncoding ( NSUTF8StringEncoding) > 0 {
142
+ if alwaysBouncePlaceholder {
143
+
144
+ _animatePlaceholder ( toRight: true )
143
145
} else {
144
- if alwaysBouncePlaceholder {
145
- _animatePlaceholder ( toRight: false )
146
- } else {
147
- lt_placeholderLabel. hidden = false
148
- }
146
+ lt_placeholderLabel. hidden = true
147
+ }
148
+ } else {
149
+ if alwaysBouncePlaceholder {
150
+ _animatePlaceholder ( toRight: false )
151
+ } else {
152
+ lt_placeholderLabel. hidden = false
149
153
}
150
154
}
151
155
}
@@ -181,23 +185,23 @@ public class LTBouncyTextField : UITextField {
181
185
}
182
186
183
187
private func _animatePlaceholder ( toRight toRight: Bool ) {
184
- if let abbrPlaceholder = abbreviatedPlaceholder {
188
+ if let _ = abbreviatedPlaceholder {
185
189
if ( toRight) {
186
- if lt_rightPlaceholderLabel. layer. presentationLayer ( ) . opacity > 0 {
190
+ if lt_rightPlaceholderLabel. layer. presentationLayer ( ) ? . opacity > 0 {
187
191
return
188
192
}
189
-
193
+
190
194
lt_placeholderLabel. layer. removeAllAnimations ( )
191
195
lt_rightPlaceholderLabel. layer. removeAllAnimations ( )
192
-
196
+
193
197
let bounceToRight = CAKeyframeAnimation ( keyPath: " position.x " )
194
198
bounceToRight. timingFunction = CAMediaTimingFunction ( name: kCAMediaTimingFunctionLinear)
195
199
bounceToRight. duration = kAnimationDuration
196
200
bounceToRight. values = _bounceKeyframes ( toRight: true ) as [ AnyObject ]
197
201
bounceToRight. fillMode = kCAFillModeForwards
198
202
bounceToRight. additive = true
199
203
bounceToRight. removedOnCompletion = false
200
-
204
+
201
205
let fadeOut = CABasicAnimation ( keyPath: " opacity " )
202
206
fadeOut. timingFunction = CAMediaTimingFunction ( name: kCAMediaTimingFunctionLinear)
203
207
fadeOut. fromValue = 1
@@ -207,29 +211,29 @@ public class LTBouncyTextField : UITextField {
207
211
fadeOut. removedOnCompletion = false
208
212
lt_placeholderLabel. layer. addAnimation ( bounceToRight, forKey: " bounceToRight " )
209
213
lt_placeholderLabel. layer. addAnimation ( fadeOut, forKey: " fadeOut " )
210
-
214
+
211
215
let fadeIn = CABasicAnimation ( keyPath: " opacity " )
212
216
fadeIn. timingFunction = CAMediaTimingFunction ( name: kCAMediaTimingFunctionLinear)
213
217
fadeIn. fromValue = 0
214
218
fadeIn. toValue = 1
215
219
fadeIn. duration = kAnimationDuration / 3
216
220
fadeIn. fillMode = kCAFillModeForwards
217
221
fadeIn. removedOnCompletion = false
218
-
222
+
219
223
lt_rightPlaceholderLabel. layer. addAnimation ( bounceToRight, forKey: " bounceToRight " )
220
224
lt_rightPlaceholderLabel. layer. addAnimation ( fadeIn, forKey: " fadeIn " )
221
225
} else {
222
226
lt_placeholderLabel. layer. removeAllAnimations ( )
223
227
lt_rightPlaceholderLabel. layer. removeAllAnimations ( )
224
-
228
+
225
229
let bounceToLeft = CAKeyframeAnimation ( keyPath: " position.x " )
226
230
bounceToLeft. timingFunction = CAMediaTimingFunction ( name: kCAMediaTimingFunctionLinear)
227
231
bounceToLeft. duration = kAnimationDuration
228
232
bounceToLeft. values = _bounceKeyframes ( toRight: false ) as [ AnyObject ]
229
233
bounceToLeft. fillMode = kCAFillModeForwards
230
234
bounceToLeft. additive = true
231
235
bounceToLeft. removedOnCompletion = false
232
-
236
+
233
237
let fadeIn = CABasicAnimation ( keyPath: " opacity " )
234
238
fadeIn. timingFunction = CAMediaTimingFunction ( name: kCAMediaTimingFunctionEaseIn)
235
239
fadeIn. duration = kAnimationDuration / 3
@@ -239,7 +243,7 @@ public class LTBouncyTextField : UITextField {
239
243
fadeIn. removedOnCompletion = false
240
244
lt_placeholderLabel. layer. addAnimation ( fadeIn, forKey: " fadeIn " )
241
245
lt_placeholderLabel. layer. addAnimation ( bounceToLeft, forKey: " bounceToLeft " )
242
-
246
+
243
247
let fadeOut = CABasicAnimation ( keyPath: " opacity " )
244
248
fadeOut. timingFunction = CAMediaTimingFunction ( name: kCAMediaTimingFunctionEaseIn)
245
249
fadeOut. duration = kAnimationDuration / 3
0 commit comments