Skip to content

Commit 4577e94

Browse files
authored
Merge pull request #9 from lauramarson/hidekeyboard
arrumado teclado que não sumia
2 parents a79f753 + 92cfcb6 commit 4577e94

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

AnimalsApp/AnimalsApp/Views/RegisterViewController/RegisterViewController.swift

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ class RegisterViewController: UIViewController {
3232
super.viewDidLoad()
3333
setupUI()
3434
setNavigationItens()
35-
}
36-
37-
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
38-
self.view.endEditing(true)
35+
delegateTextField()
3936
}
4037

4138
// MARK: Actions
@@ -74,4 +71,20 @@ class RegisterViewController: UIViewController {
7471
parameters["specie"] = textFieldSpecie.text
7572
parameters["image"] = textFieldImageLink.text
7673
}
74+
75+
private func delegateTextField() {
76+
textFieldAge.delegate = self
77+
textFieldName.delegate = self
78+
textFieldDescription.delegate = self
79+
textFieldSpecie.delegate = self
80+
textFieldImageLink.delegate = self
81+
self.view.addGestureRecognizer(UITapGestureRecognizer(target: self.view, action: #selector(UIView.endEditing(_:))))
82+
}
83+
}
84+
85+
extension RegisterViewController: UIGestureRecognizerDelegate, UITextFieldDelegate {
86+
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
87+
textField.resignFirstResponder()
88+
return true
89+
}
7790
}

AnimalsApp/AnimalsApp/Views/RegisterViewController/RegisterViewController.xib

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<constraint firstAttribute="height" constant="56" id="zQR-K7-ZE5"/>
4747
</constraints>
4848
<fontDescription key="fontDescription" type="system" pointSize="14"/>
49-
<textInputTraits key="textInputTraits"/>
49+
<textInputTraits key="textInputTraits" returnKeyType="done"/>
5050
</textField>
5151
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Link da imagem" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="xF5-Gv-lri">
5252
<rect key="frame" x="0.0" y="81" width="388" height="56"/>
@@ -55,7 +55,7 @@
5555
<constraint firstAttribute="height" constant="56" id="eD1-EJ-ECA"/>
5656
</constraints>
5757
<fontDescription key="fontDescription" type="system" pointSize="14"/>
58-
<textInputTraits key="textInputTraits"/>
58+
<textInputTraits key="textInputTraits" returnKeyType="done"/>
5959
</textField>
6060
</subviews>
6161
<constraints>
@@ -71,7 +71,7 @@
7171
<constraint firstAttribute="height" constant="56" id="aIE-KD-e76"/>
7272
</constraints>
7373
<fontDescription key="fontDescription" type="system" pointSize="14"/>
74-
<textInputTraits key="textInputTraits"/>
74+
<textInputTraits key="textInputTraits" returnKeyType="done"/>
7575
</textField>
7676
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Espécie" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="rD2-wq-owE">
7777
<rect key="frame" x="0.0" y="81" width="388" height="56"/>
@@ -80,7 +80,7 @@
8080
<constraint firstAttribute="height" constant="56" id="FNP-bJ-jHT"/>
8181
</constraints>
8282
<fontDescription key="fontDescription" type="system" pointSize="14"/>
83-
<textInputTraits key="textInputTraits"/>
83+
<textInputTraits key="textInputTraits" returnKeyType="done"/>
8484
</textField>
8585
</subviews>
8686
<constraints>
@@ -99,7 +99,7 @@
9999
<constraint firstAttribute="height" constant="56" id="liL-v1-2oa"/>
100100
</constraints>
101101
<fontDescription key="fontDescription" type="system" pointSize="14"/>
102-
<textInputTraits key="textInputTraits"/>
102+
<textInputTraits key="textInputTraits" keyboardType="numberPad" returnKeyType="done"/>
103103
</textField>
104104
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="IgQ-5e-alS">
105105
<rect key="frame" x="0.0" y="81" width="388" height="59"/>

0 commit comments

Comments
 (0)