Skip to content

Commit c6b24b4

Browse files
committed
Swift3
2 parents 5b0b058 + 6f7d6ad commit c6b24b4

File tree

8 files changed

+179
-148
lines changed

8 files changed

+179
-148
lines changed

Example/NextGrowingTextView/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1414
var window: UIWindow?
1515

1616

17-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
17+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
1818
// Override point for customization after application launch.
1919
return true
2020
}

Example/NextGrowingTextView/ViewController.swift

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,46 +36,52 @@ class ViewController: UIViewController {
3636
NotificationCenter.default.addObserver(self, selector: #selector(ViewController.keyboardWillShow(_:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
3737

3838
NotificationCenter.default.addObserver(self, selector: #selector(ViewController.keyboardWillHide(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
39-
40-
growingTextView.layer.cornerRadius = 4
41-
growingTextView.backgroundColor = UIColor(white: 0.9, alpha: 1)
42-
growingTextView.textContainerInset = UIEdgeInsets(top: 16, left: 0, bottom: 4, right: 0)
43-
growingTextView.placeholderAttributedText = NSAttributedString(string: "Placeholder text",
44-
attributes: [NSFontAttributeName: growingTextView.font!,
39+
40+
self.growingTextView.layer.cornerRadius = 4
41+
self.growingTextView.backgroundColor = UIColor(white: 0.9, alpha: 1)
42+
self.growingTextView.textContainerInset = UIEdgeInsets(top: 16, left: 0, bottom: 4, right: 0)
43+
self.growingTextView.placeholderAttributedText = NSAttributedString(string: "Placeholder text",
44+
attributes: [NSFontAttributeName: self.growingTextView.font!,
4545
NSForegroundColorAttributeName: UIColor.gray
4646
]
4747
)
48+
4849
}
4950

5051
override func didReceiveMemoryWarning() {
5152
super.didReceiveMemoryWarning()
5253
// Dispose of any resources that can be recreated.
5354
}
5455
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
55-
view.endEditing(true)
56+
self.view.endEditing(true)
5657
}
5758

59+
5860
@IBAction func handleSendButton(_ sender: AnyObject) {
59-
growingTextView.text = ""
60-
view.endEditing(true)
61+
self.growingTextView.text = ""
62+
self.view.endEditing(true)
6163
}
6264

6365

6466
func keyboardWillHide(_ sender: Notification) {
65-
66-
//key point 0,
67-
inputContainerViewBottom.constant = 0
68-
//textViewBottomConstraint.constant = keyboardHeight
69-
UIView.animate(withDuration: 0.25, animations: { () -> Void in self.view.layoutIfNeeded() })
67+
if let userInfo = (sender as NSNotification).userInfo {
68+
if let _ = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue.size.height {
69+
//key point 0,
70+
self.inputContainerViewBottom.constant = 0
71+
//textViewBottomConstraint.constant = keyboardHeight
72+
UIView.animate(withDuration: 0.25, animations: { () -> Void in self.view.layoutIfNeeded() })
73+
}
74+
}
7075
}
7176
func keyboardWillShow(_ sender: Notification) {
72-
guard let keyboardHeight = (sender.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue.size.height else {
73-
return
74-
}
75-
inputContainerViewBottom.constant = keyboardHeight
76-
UIView.animate(withDuration: 0.25, animations: { () -> Void in
77-
self.view.layoutIfNeeded()
78-
})
77+
if let userInfo = (sender as NSNotification).userInfo {
78+
if let keyboardHeight = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue.size.height {
79+
self.inputContainerViewBottom.constant = keyboardHeight
80+
UIView.animate(withDuration: 0.25, animations: { () -> Void in
81+
self.view.layoutIfNeeded()
82+
})
83+
}
84+
}
7985
}
8086
}
8187

Example/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 30 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/NextGrowingTextView.xcscheme

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/NextGrowingTextView/Info.plist

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/Pods-NextGrowingTextView_Example/Info.plist

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)