Skip to content

Commit ebf8fff

Browse files
authored
Merge pull request #14 from lauramarson/keyboardChanges
adapts scrollView size to keyboard
2 parents 17d4a25 + 49d7e10 commit ebf8fff

6 files changed

Lines changed: 147 additions & 157 deletions

File tree

AnimalsApp/AnimalsApp/Assets.xcassets/Colors/grayTextColor.colorset/Contents.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"color-space" : "srgb",
66
"components" : {
77
"alpha" : "1.000",
8-
"blue" : "0.400",
9-
"green" : "0.400",
10-
"red" : "0.400"
8+
"blue" : "0x66",
9+
"green" : "0x66",
10+
"red" : "0x66"
1111
}
1212
},
1313
"idiom" : "universal"

AnimalsApp/AnimalsApp/DesignSystem/Colors.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ extension UIColor {
1111
static let blueTabBarColor: UIColor? = UIColor(named: "blueTabBarColor")
1212
static let blueTextColor: UIColor? = UIColor(named: "blueTextColor")
1313

14+
static let grayCellFrame: UIColor? = UIColor(named: "grayCellFrame")
15+
static let grayTextColor: UIColor? = UIColor(named: "grayTextColor")
1416
static let lightGray: UIColor? = UIColor(named: "lightGray")
1517

1618
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// Colors.swift
3+
// AnimalsApp
4+
//
5+
// Created by Laura Pinheiro Marson on 16/06/22.
6+
//
7+
8+
import UIKit
9+
10+
extension UIColor {
11+
static let blueTabBarColor: UIColor? = UIColor(named: "blueTabBarColor")
12+
static let blueTextColor: UIColor? = UIColor(named: "blueTextColor")
13+
14+
<<<<<<< HEAD
15+
static let grayCellFrame: UIColor? = UIColor(named: "grayCellFrame")
16+
static let grayTextColor: UIColor? = UIColor(named: "grayTextColor")
17+
=======
18+
static let lightGray: UIColor? = UIColor(named: "lightGray")
19+
20+
>>>>>>> develop
21+
}

AnimalsApp/AnimalsApp/Views/Components/AnimalTableViewCell.xib

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@
3131
</constraints>
3232
</imageView>
3333
<button opaque="NO" contentMode="scaleAspectFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="687-rn-Ydp">
34-
<rect key="frame" x="247" y="33" width="40" height="30"/>
34+
<rect key="frame" x="247" y="28" width="40" height="40"/>
3535
<constraints>
36-
<constraint firstAttribute="height" constant="30" id="7rZ-bg-lFP"/>
36+
<constraint firstAttribute="height" constant="40" id="7rZ-bg-lFP"/>
3737
<constraint firstAttribute="width" constant="40" id="i65-df-ED5"/>
3838
</constraints>
39-
<inset key="imageEdgeInsets" minX="35" minY="0.0" maxX="35" maxY="0.0"/>
4039
<state key="normal" image="addFavorite"/>
4140
<connections>
4241
<action selector="favoritePressed:" destination="KGk-i7-Jjw" eventType="touchUpInside" id="X9N-Mv-iRU"/>

AnimalsApp/AnimalsApp/Views/RegisterViewController/RegisterViewController.swift

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,43 @@ import Alamofire
1010

1111
class 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

95120
extension RegisterViewController: UIGestureRecognizerDelegate, UITextFieldDelegate {

0 commit comments

Comments
 (0)