Skip to content

Commit 1b5ac69

Browse files
author
Jett Farmer
committed
Updated pods. Changed formatting to improve readability.
1 parent 0182872 commit 1b5ac69

File tree

5 files changed

+109
-111
lines changed

5 files changed

+109
-111
lines changed

Example/Podfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ abstract_target 'AMResizingTextView_Abstract_Target' do
88
end
99

1010
target 'AMResizingTextView_Tests' do
11-
pod 'Nimble', :git => 'https://github.com/Quick/Nimble', :commit => '4b539a2'
12-
end
11+
pod 'Nimble', :git => 'https://github.com/Quick/Nimble', :branch => 'swift-3.0'
12+
end
1313
end

Example/Podfile.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ PODS:
44

55
DEPENDENCIES:
66
- AMResizingTextView (from `../`)
7-
- Nimble (from `https://github.com/Quick/Nimble`, commit `4b539a2`)
7+
- Nimble (from `https://github.com/Quick/Nimble`, branch `swift-3.0`)
88

99
EXTERNAL SOURCES:
1010
AMResizingTextView:
1111
:path: "../"
1212
Nimble:
13-
:commit: 4b539a2
13+
:branch: swift-3.0
1414
:git: https://github.com/Quick/Nimble
1515

1616
CHECKOUT OPTIONS:
1717
Nimble:
18-
:commit: 4b539a2
18+
:commit: 220152be528dcc0537764c179c95b8174028c80c
1919
:git: https://github.com/Quick/Nimble
2020

2121
SPEC CHECKSUMS:
2222
AMResizingTextView: e404e9e37759ead1fe8d7c1ead70383554c402d8
2323
Nimble: c5b995b4cd57789ec44b0cfb79640fc00e61a8c7
2424

25-
PODFILE CHECKSUM: 7adb80edbc90358c3ed781cc82d2e53a1aeb4ae2
25+
PODFILE CHECKSUM: 99dd35b0c2d82044b664d1d1aca7bdc96c22ba53
2626

2727
COCOAPODS: 1.0.1

Example/Pods/Manifest.lock

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Nimble/Sources/Nimble/Adapters/NMBObjCMatcher.swift

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pod/Classes/ResizingTextView.swift

+94-96
Original file line numberDiff line numberDiff line change
@@ -2,104 +2,102 @@ import UIKit
22

33
/**
44
A `UITextView` subclass that automatically resizes based on the size of its content text with a smooth animation.
5-
*/
5+
*/
66
open class ResizingTextView: UITextView {
7-
8-
/*
9-
* MARK: - Instance Properties
10-
*/
11-
12-
/// The duration of the animation while resizing the text view in seconds. Defaults to `0.1`.
13-
var resizeDuration: TimeInterval = 0.1
14-
15-
fileprivate var heightConstraint: NSLayoutConstraint!
16-
17-
/*
18-
* MARK: - Object Lifecycle
19-
*/
20-
21-
override init(frame: CGRect, textContainer: NSTextContainer?) {
22-
super.init(frame: frame, textContainer: textContainer)
23-
24-
commonInit()
25-
}
26-
27-
public required init?(coder aDecoder: NSCoder) {
28-
super.init(coder: aDecoder)
29-
30-
commonInit()
31-
}
32-
33-
fileprivate func commonInit() {
34-
attachHeightConstraint()
35-
registerForTextChangeNotification()
36-
}
37-
38-
fileprivate func attachHeightConstraint() {
39-
if !findHeightConstraint() {
40-
createHeightConstraint()
7+
8+
/*
9+
* MARK: - Instance Properties
10+
*/
11+
12+
/// The duration of the animation while resizing the text view in seconds. Defaults to `0.1`.
13+
var resizeDuration: TimeInterval = 0.1
14+
15+
fileprivate var heightConstraint: NSLayoutConstraint!
16+
17+
/*
18+
* MARK: - Object Lifecycle
19+
*/
20+
21+
override init(frame: CGRect, textContainer: NSTextContainer?) {
22+
super.init(frame: frame, textContainer: textContainer)
23+
24+
commonInit()
25+
}
26+
27+
public required init?(coder aDecoder: NSCoder) {
28+
super.init(coder: aDecoder)
29+
30+
commonInit()
31+
}
32+
33+
fileprivate func commonInit() {
34+
attachHeightConstraint()
35+
registerForTextChangeNotification()
36+
}
37+
38+
fileprivate func attachHeightConstraint() {
39+
if !findHeightConstraint() {
40+
createHeightConstraint()
41+
}
42+
}
43+
44+
fileprivate func findHeightConstraint() -> Bool {
45+
for constraint in constraints {
46+
if constraint.firstAttribute == .height {
47+
heightConstraint = constraint
48+
return true
49+
}
50+
}
51+
return false
52+
}
53+
54+
fileprivate func createHeightConstraint() {
55+
heightConstraint = NSLayoutConstraint(item: self,
56+
attribute: .height,
57+
relatedBy: .equal,
58+
toItem: nil,
59+
attribute: .notAnAttribute,
60+
multiplier: 1.0,
61+
constant: heightForCurrentText())
62+
63+
addConstraint(heightConstraint)
4164
}
42-
}
43-
44-
fileprivate func findHeightConstraint() -> Bool {
45-
for constraint in constraints {
46-
if constraint.firstAttribute == .height {
47-
heightConstraint = constraint
48-
return true
49-
}
65+
66+
fileprivate func heightForCurrentText() -> CGFloat {
67+
return sizeThatFits(self.frame.size).height
5068
}
51-
return false
52-
}
53-
54-
fileprivate func createHeightConstraint() {
55-
heightConstraint = NSLayoutConstraint(item: self,
56-
attribute: .height,
57-
relatedBy: .equal,
58-
toItem: nil,
59-
attribute: .notAnAttribute,
60-
multiplier: 1.0,
61-
constant: heightForCurrentText())
62-
63-
addConstraint(heightConstraint)
64-
}
65-
66-
fileprivate func heightForCurrentText() -> CGFloat {
67-
return sizeThatFits(self.frame.size).height
68-
}
69-
70-
fileprivate func registerForTextChangeNotification() {
71-
NotificationCenter.default.addObserver(self,
72-
selector: #selector(ResizingTextView.didUpdateText(_:)),
73-
name: NSNotification.Name.UITextViewTextDidChange,
74-
object: self)
75-
}
76-
77-
deinit {
78-
NotificationCenter.default.removeObserver(self)
79-
}
80-
81-
/*
82-
* MARK: - Auto Resizing
83-
*/
84-
85-
func didUpdateText(_ sender: AnyObject) {
86-
let newHeight = heightForCurrentText()
87-
if newHeight != heightConstraint.constant {
88-
updateHeightConstraint(newHeight)
69+
70+
fileprivate func registerForTextChangeNotification() {
71+
NotificationCenter.default.addObserver(self,
72+
selector: #selector(ResizingTextView.didUpdateText(_:)),
73+
name: NSNotification.Name.UITextViewTextDidChange,
74+
object: self)
75+
}
76+
77+
deinit {
78+
NotificationCenter.default.removeObserver(self)
8979
}
90-
}
91-
92-
fileprivate func updateHeightConstraint(_ newHeight: CGFloat) {
93-
heightConstraint.constant = newHeight
94-
setNeedsLayout()
95-
96-
UIView.animate(withDuration: resizeDuration,
97-
delay: 0,
98-
options: .layoutSubviews,
99-
animations: { () -> Void in
100-
self.layoutIfNeeded()
101-
},
102-
completion: nil)
103-
}
104-
80+
81+
/*
82+
* MARK: - Auto Resizing
83+
*/
84+
85+
func didUpdateText(_ sender: AnyObject) {
86+
let newHeight = heightForCurrentText()
87+
if newHeight != heightConstraint.constant {
88+
updateHeightConstraint(newHeight)
89+
}
90+
}
91+
92+
fileprivate func updateHeightConstraint(_ newHeight: CGFloat) {
93+
heightConstraint.constant = newHeight
94+
setNeedsLayout()
95+
96+
UIView.animate(withDuration: resizeDuration,
97+
delay: 0,
98+
options: .layoutSubviews,
99+
animations: { self.layoutIfNeeded() },
100+
completion: nil)
101+
}
102+
105103
}

0 commit comments

Comments
 (0)