Skip to content

Commit 4e963d4

Browse files
committed
Fix compile error.
1 parent 97b208e commit 4e963d4

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

LTBouncyPlaceholder/UITextField+LTBouncyPlaceholder.swift

+27-23
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,24 @@ public class LTBouncyTextField : UITextField {
132132
}
133133

134134
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)
143145
} 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
149153
}
150154
}
151155
}
@@ -181,23 +185,23 @@ public class LTBouncyTextField : UITextField {
181185
}
182186

183187
private func _animatePlaceholder (toRight toRight: Bool) {
184-
if let abbrPlaceholder = abbreviatedPlaceholder {
188+
if let _ = abbreviatedPlaceholder {
185189
if (toRight) {
186-
if lt_rightPlaceholderLabel.layer.presentationLayer().opacity > 0 {
190+
if lt_rightPlaceholderLabel.layer.presentationLayer()?.opacity > 0 {
187191
return
188192
}
189-
193+
190194
lt_placeholderLabel.layer.removeAllAnimations()
191195
lt_rightPlaceholderLabel.layer.removeAllAnimations()
192-
196+
193197
let bounceToRight = CAKeyframeAnimation(keyPath: "position.x")
194198
bounceToRight.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
195199
bounceToRight.duration = kAnimationDuration
196200
bounceToRight.values = _bounceKeyframes(toRight: true) as [AnyObject]
197201
bounceToRight.fillMode = kCAFillModeForwards
198202
bounceToRight.additive = true
199203
bounceToRight.removedOnCompletion = false
200-
204+
201205
let fadeOut = CABasicAnimation(keyPath: "opacity")
202206
fadeOut.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
203207
fadeOut.fromValue = 1
@@ -207,29 +211,29 @@ public class LTBouncyTextField : UITextField {
207211
fadeOut.removedOnCompletion = false
208212
lt_placeholderLabel.layer.addAnimation(bounceToRight, forKey: "bounceToRight")
209213
lt_placeholderLabel.layer.addAnimation(fadeOut, forKey: "fadeOut")
210-
214+
211215
let fadeIn = CABasicAnimation(keyPath: "opacity")
212216
fadeIn.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
213217
fadeIn.fromValue = 0
214218
fadeIn.toValue = 1
215219
fadeIn.duration = kAnimationDuration / 3
216220
fadeIn.fillMode = kCAFillModeForwards
217221
fadeIn.removedOnCompletion = false
218-
222+
219223
lt_rightPlaceholderLabel.layer.addAnimation(bounceToRight, forKey: "bounceToRight")
220224
lt_rightPlaceholderLabel.layer.addAnimation(fadeIn, forKey: "fadeIn")
221225
} else {
222226
lt_placeholderLabel.layer.removeAllAnimations()
223227
lt_rightPlaceholderLabel.layer.removeAllAnimations()
224-
228+
225229
let bounceToLeft = CAKeyframeAnimation(keyPath: "position.x")
226230
bounceToLeft.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
227231
bounceToLeft.duration = kAnimationDuration
228232
bounceToLeft.values = _bounceKeyframes(toRight: false) as [AnyObject]
229233
bounceToLeft.fillMode = kCAFillModeForwards
230234
bounceToLeft.additive = true
231235
bounceToLeft.removedOnCompletion = false
232-
236+
233237
let fadeIn = CABasicAnimation(keyPath: "opacity")
234238
fadeIn.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn)
235239
fadeIn.duration = kAnimationDuration / 3
@@ -239,7 +243,7 @@ public class LTBouncyTextField : UITextField {
239243
fadeIn.removedOnCompletion = false
240244
lt_placeholderLabel.layer.addAnimation(fadeIn, forKey: "fadeIn")
241245
lt_placeholderLabel.layer.addAnimation(bounceToLeft, forKey: "bounceToLeft")
242-
246+
243247
let fadeOut = CABasicAnimation(keyPath: "opacity")
244248
fadeOut.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn)
245249
fadeOut.duration = kAnimationDuration / 3

0 commit comments

Comments
 (0)