@@ -10,39 +10,43 @@ import Alamofire
1010
1111class RegisterViewController : UIViewController {
1212 // MARK: Properties
13- var registerVM = RegisterViewModel ( )
13+ private var registerVM = RegisterViewModel ( )
1414
1515 // MARK: Outlets
16+ @IBOutlet weak var scrollView : UIScrollView !
1617 @IBOutlet weak var textFieldName : UITextField !
1718 @IBOutlet weak var textFieldImageLink : UITextField !
1819 @IBOutlet weak var textFieldDescription : UITextField !
1920 @IBOutlet weak var textFieldSpecie : UITextField !
2021 @IBOutlet weak var textFieldAge : UITextField !
2122 @IBOutlet weak var buttonRegister : UIButton !
22- @IBOutlet weak var activityIndicator : UIActivityIndicatorView !
23+ // @IBOutlet weak var activityIndicator: UIActivityIndicatorView!
2324
2425 // MARK: Overrides
2526 override func viewDidLoad( ) {
2627 super. viewDidLoad ( )
2728 setupUI ( )
2829 setNavigationItems ( )
2930 delegateTextField ( )
30- activityIndicator. hidesWhenStopped = true
31+ notificationCenter ( )
32+ // activityIndicator.hidesWhenStopped = true
3133 }
3234
3335 // MARK: Actions
3436 @IBAction func handlerButtonRegister( _ sender: Any ) {
37+
3538 guard let name = textFieldName. text? . testIfIsEmpty ( ) ,
3639 let description = textFieldDescription. text? . testIfIsEmpty ( ) ,
3740 let age = Int ( textFieldAge. text ?? " " ) ,
3841 let species = textFieldSpecie. text? . testIfIsEmpty ( ) ,
3942 let image = textFieldImageLink. text? . testIfIsEmpty ( ) else {
40- showAlerts ( alertTitle: " Erro " , alertMessage: " Preencha todos os dados " )
43+ showAlerts ( alertTitle: " Erro " , alertMessage: " Preencha todos os campos " )
4144 return }
4245
43- activityIndicator. startAnimating ( )
46+ // activityIndicator.startAnimating()
4447 registerVM. registerAnimal ( name: name, description: description, age: age, species: species, image: image) {
45- self . activityIndicator. stopAnimating ( )
48+ // self.activityIndicator.stopAnimating()
49+ print ( " oi " )
4650 }
4751 }
4852
@@ -63,16 +67,16 @@ class RegisterViewController: UIViewController {
6367 [ textFieldName, textFieldImageLink, textFieldDescription, textFieldSpecie, textFieldAge] . forEach { textField in
6468 textField? . layer. cornerRadius = 8
6569 textField? . layer. borderWidth = 1
66- textField? . layer. borderColor = UIColor . systemGray . cgColor
70+ textField? . layer. borderColor = UIColor . grayCellFrame ? . cgColor
6771 textField? . layer. masksToBounds = true
6872 }
6973
70- let attributes = [ NSAttributedString . Key. foregroundColor: UIColor . systemGray]
71- textFieldName. attributedPlaceholder = NSAttributedString ( string: " Nome " , attributes: attributes)
72- textFieldImageLink. attributedPlaceholder = NSAttributedString ( string: " Link da imagem " , attributes: attributes)
73- textFieldDescription. attributedPlaceholder = NSAttributedString ( string: " Descrição " , attributes: attributes)
74- textFieldSpecie. attributedPlaceholder = NSAttributedString ( string: " Espécie " , attributes: attributes)
75- textFieldAge. attributedPlaceholder = NSAttributedString ( string: " Idade " , attributes: attributes)
74+ let attributes = [ NSAttributedString . Key. foregroundColor: UIColor . grayTextColor ?? UIColor . systemGray, NSAttributedString . Key . font : UIFont ( name : " OpenSans " , size : 16 ) ?? UIFont . systemFont ( ofSize : 16 ) ]
75+ textFieldName. attributedPlaceholder = NSAttributedString ( string: " Nome" , attributes: attributes)
76+ textFieldImageLink. attributedPlaceholder = NSAttributedString ( string: " Link da imagem" , attributes: attributes)
77+ textFieldDescription. attributedPlaceholder = NSAttributedString ( string: " Descrição" , attributes: attributes)
78+ textFieldSpecie. attributedPlaceholder = NSAttributedString ( string: " Espécie" , attributes: attributes)
79+ textFieldAge. attributedPlaceholder = NSAttributedString ( string: " Idade" , attributes: attributes)
7680 buttonRegister. layer. cornerRadius = 10
7781 }
7882
@@ -90,6 +94,27 @@ class RegisterViewController: UIViewController {
9094 alert. addAction ( UIAlertAction ( title: " OK " , style: . default, handler: nil ) )
9195 present ( alert, animated: true )
9296 }
97+
98+ private func notificationCenter( ) {
99+ let notificationCenter = NotificationCenter . default
100+ notificationCenter. addObserver ( self , selector: #selector( adjustForKeyboard) , name: UIResponder . keyboardWillHideNotification, object: nil )
101+ notificationCenter. addObserver ( self , selector: #selector( adjustForKeyboard) , name: UIResponder . keyboardWillChangeFrameNotification, object: nil )
102+ }
103+
104+ @objc func adjustForKeyboard( notification: Notification ) {
105+ guard let keyboardValue = notification. userInfo ? [ UIResponder . keyboardFrameEndUserInfoKey] as? NSValue else { return }
106+
107+ let keyboardScreenEndFrame = keyboardValue. cgRectValue
108+ let keyboardViewEndFrame = view. convert ( keyboardScreenEndFrame, from: view. window)
109+
110+ if notification. name == UIResponder . keyboardWillHideNotification {
111+ scrollView. contentInset = . zero
112+ } else {
113+ scrollView. contentInset = UIEdgeInsets ( top: 0 , left: 0 , bottom: keyboardViewEndFrame. height - view. safeAreaInsets. bottom, right: 0 )
114+ }
115+
116+ scrollView. scrollIndicatorInsets = scrollView. contentInset
117+ }
93118}
94119
95120extension RegisterViewController : UIGestureRecognizerDelegate , UITextFieldDelegate {
0 commit comments