Skip to content

Commit c9d2bad

Browse files
committed
Yoko bug fix, and simplified the code, should check all other effects for something like this
1 parent 30b4af4 commit c9d2bad

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

TextFieldEffects/TextFieldEffects/YokoTextField.swift

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ import UIKit
3030

3131
override var bounds: CGRect {
3232
didSet {
33-
drawViewsForRect(bounds)
33+
updateForeground()
34+
updatePlaceholder()
3435
}
3536
}
3637

@@ -41,16 +42,7 @@ import UIKit
4142
private let textFieldInsets = CGPoint(x: 6, y: 6)
4243

4344
override func drawViewsForRect(rect: CGRect) {
44-
let frame = CGRect(origin: CGPointZero, size: CGSize(width: rect.size.width, height: rect.size.height))
45-
46-
foregroundView.frame = rectForForeground(rect)
47-
foregroundView.userInteractionEnabled = false
48-
foregroundView.layer.transform = rotationAndPerspectiveTransformForView(foregroundView)
49-
updateForeground()
50-
51-
placeholderLabel.frame = CGRectInset(rect, placeholderInsets.x, placeholderInsets.y)
52-
placeholderLabel.font = placeholderFontFromFont(font)
53-
45+
updateForeground()
5446
updatePlaceholder()
5547

5648
addSubview(foregroundView)
@@ -61,6 +53,9 @@ import UIKit
6153
}
6254

6355
private func updateForeground() {
56+
foregroundView.frame = rectForForeground(frame)
57+
foregroundView.userInteractionEnabled = false
58+
foregroundView.layer.transform = rotationAndPerspectiveTransformForView(foregroundView)
6459
foregroundView.backgroundColor = foregroundColor
6560

6661
foregroundLayer.borderWidth = borderThickness
@@ -69,12 +64,13 @@ import UIKit
6964
}
7065

7166
private func updatePlaceholder() {
67+
placeholderLabel.font = placeholderFontFromFont(font)
7268
placeholderLabel.text = placeholder
7369
placeholderLabel.textColor = placeholderColor
7470
placeholderLabel.sizeToFit()
7571
layoutPlaceholderInTextRect()
7672

77-
if isFirstResponder() {
73+
if isFirstResponder() || !text.isEmpty {
7874
animateViewsForTextEntry()
7975
}
8076
}
@@ -101,11 +97,6 @@ import UIKit
10197
}
10298

10399
private func layoutPlaceholderInTextRect() {
104-
105-
if !text.isEmpty {
106-
return
107-
}
108-
109100
let textRect = textRectForBounds(bounds)
110101
var originX = textRect.origin.x
111102
switch textAlignment {
@@ -121,7 +112,7 @@ import UIKit
121112
}
122113

123114
override func animateViewsForTextEntry() {
124-
UIView.animateWithDuration(0.4, delay: 0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0.6, options: UIViewAnimationOptions.BeginFromCurrentState, animations: { () -> Void in
115+
UIView.animateWithDuration(0.4, delay: 0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0.6, options: UIViewAnimationOptions.BeginFromCurrentState, animations: { () -> Void in
125116

126117
self.foregroundView.layer.transform = CATransform3DIdentity
127118

0 commit comments

Comments
 (0)