@@ -24,64 +24,63 @@ import UIKit
2424import NextGrowingTextView
2525
2626class ViewController : UIViewController {
27-
28- @IBOutlet weak var inputContainerView : UIView !
29- @IBOutlet weak var inputContainerViewBottom : NSLayoutConstraint !
30- @IBOutlet weak var growingTextView : NextGrowingTextView !
31-
32- override func viewDidLoad( ) {
33- super. viewDidLoad ( )
34- // Do any additional setup after loading the view, typically from a nib.
35-
36- NotificationCenter . default. addObserver ( self , selector: #selector( ViewController . keyboardWillShow ( _: ) ) , name: NSNotification . Name. UIKeyboardWillShow, object: nil )
37-
38- NotificationCenter . default. addObserver ( self , selector: #selector( ViewController . keyboardWillHide ( _: ) ) , name: NSNotification . Name. UIKeyboardWillHide, object: nil )
39-
40- self . growingTextView. layer. cornerRadius = 4
41- self . growingTextView. backgroundColor = UIColor ( white: 0.9 , alpha: 1 )
42- self . growingTextView. textView. textContainerInset = UIEdgeInsets ( top: 4 , left: 0 , bottom: 4 , right: 0 )
43- self . growingTextView. placeholderAttributedText = NSAttributedString ( string: " Placeholder text " ,
44- attributes: [ NSAttributedStringKey . font: self . growingTextView. textView. font!,
45- NSAttributedStringKey . foregroundColor: UIColor . gray
46- ]
47- )
48-
49- }
50-
51- override func didReceiveMemoryWarning( ) {
52- super. didReceiveMemoryWarning ( )
53- // Dispose of any resources that can be recreated.
54- }
55- override func touchesBegan( _ touches: Set < UITouch > , with event: UIEvent ? ) {
56- self . view. endEditing ( true )
57- }
58-
59-
60- @IBAction func handleSendButton( _ sender: AnyObject ) {
61- self . growingTextView. textView. text = " "
62- self . view. endEditing ( true )
63- }
64-
65-
27+
28+ @IBOutlet weak var inputContainerView : UIView !
29+ @IBOutlet weak var inputContainerViewBottom : NSLayoutConstraint !
30+ @IBOutlet weak var growingTextView : NextGrowingTextView !
31+
32+ override func viewDidLoad( ) {
33+ super. viewDidLoad ( )
34+ // Do any additional setup after loading the view, typically from a nib.
35+
36+ NotificationCenter . default. addObserver ( self , selector: #selector( ViewController . keyboardWillShow ( _: ) ) , name: NSNotification . Name. UIKeyboardWillShow, object: nil )
37+
38+ NotificationCenter . default. addObserver ( self , selector: #selector( ViewController . keyboardWillHide ( _: ) ) , name: NSNotification . Name. UIKeyboardWillHide, object: nil )
39+
40+ self . growingTextView. layer. cornerRadius = 4
41+ self . growingTextView. backgroundColor = UIColor ( white: 0.9 , alpha: 1 )
42+ self . growingTextView. placeholderAttributedText = NSAttributedString (
43+ string: " Placeholder text " ,
44+ attributes: [
45+ . font: self . growingTextView. textView. font!,
46+ . foregroundColor: UIColor . gray
47+ ]
48+ )
49+ }
50+
51+ override func didReceiveMemoryWarning( ) {
52+ super. didReceiveMemoryWarning ( )
53+ // Dispose of any resources that can be recreated.
54+ }
55+ override func touchesBegan( _ touches: Set < UITouch > , with event: UIEvent ? ) {
56+ self . view. endEditing ( true )
57+ }
58+
59+
60+ @IBAction func handleSendButton( _ sender: AnyObject ) {
61+ self . growingTextView. textView. text = " "
62+ self . view. endEditing ( true )
63+ }
64+
6665 @objc func keyboardWillHide( _ sender: Notification ) {
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- }
66+ if let userInfo = ( sender as NSNotification ) . userInfo {
67+ if let _ = ( userInfo [ UIKeyboardFrameEndUserInfoKey] as? NSValue ) ? . cgRectValue. size. height {
68+ //key point 0,
69+ self . inputContainerViewBottom. constant = 0
70+ //textViewBottomConstraint.constant = keyboardHeight
71+ UIView . animate ( withDuration: 0.25 , animations: { ( ) -> Void in self . view. layoutIfNeeded ( ) } )
72+ }
7573 }
74+ }
7675 @objc func keyboardWillShow( _ sender: Notification ) {
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- }
76+ if let userInfo = ( sender as NSNotification ) . userInfo {
77+ if let keyboardHeight = ( userInfo [ UIKeyboardFrameEndUserInfoKey] as? NSValue ) ? . cgRectValue. size. height {
78+ self . inputContainerViewBottom. constant = keyboardHeight
79+ UIView . animate ( withDuration: 0.25 , animations: { ( ) -> Void in
80+ self . view. layoutIfNeeded ( )
81+ } )
82+ }
8583 }
84+ }
8685}
8786
0 commit comments