Unable to make View up when tapping on textfield in swift4 - ios

I have textfield and button inside containerview, now if i tap on textfield i need containerview has to up with keyboard
according to this answer
for bottom view
bottom = leading = trailing = 0, height = 80
and
i have created containerview bottom constraint to NSLayoutConstraint
and addd code like this: but i am unable to move container viewup, only keyboard coming.. view not comingup, where am i wrong
class MessageDetailsVCViewController: UIViewController {
#IBOutlet weak var messageTextfield: UITextField!
#IBOutlet weak var viewbottomConstraint: NSLayoutConstraint!
#IBOutlet weak var bottomContainerView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotification), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotification), name: UIResponder.keyboardWillHideNotification, object: nil)
// Do any additional setup after loading the view.
}
override func viewWillDisappear(_ animated: Bool) {
NotificationCenter.default.removeObserver(self)
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
self.bottomContainerView.superview?.setNeedsLayout()
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
override func resignFirstResponder() -> Bool {
return true
}
#objc func handleKeyboardNotification(_ notification: Notification) {
if let userInfo = notification.userInfo {
let keyboardFrame = (userInfo[UIResponder.keyboardFrameEndUserInfoKey] as AnyObject).cgRectValue
let isKeyboardShowing = notification.name == UIResponder.keyboardWillShowNotification
viewbottomConstraint?.constant = isKeyboardShowing ? -keyboardFrame!.height : 0
UIView.animate(withDuration: 0.5, animations: { () -> Void in
self.view.layoutIfNeeded()
})
}
}
}

You can try positive keyboardFrame!.height
viewbottomConstraint?.constant = isKeyboardShowing ? keyboardFrame!.height : 0

Related

How to make scrollView scrolling only if keyboard appears in swift

I am using scrolview for view with height 1000, initially i don't want my scrolView to scroll. if i tap on any textField then i want my scrolview to scroll and if i return keyboard then i don't want my scrollview to scroll.
Here i am able to textfield up when when keyboard appears but i am unable to return textfield to its orginal position when i return keyboard and when i return keyboard i dont want my view to scroll,
Please help me in the code.
class ViewController: UIViewController, UITextFieldDelegate {
#IBOutlet weak var scrolView: UIScrollView!
#IBOutlet weak var upTFLD: UITextField!
var activeTextField = UITextField()
#IBOutlet weak var downTFLD: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
upTFLD.delegate = self
downTFLD.delegate = self
NotificationCenter.default.addObserver(self, selector: #selector(onKeyboardAppear(_:)), name: UIResponder.keyboardDidShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(onKeyboardDisappear(_:)), name: UIResponder.keyboardDidHideNotification, object: nil)
}
#objc func onKeyboardAppear(_ notification: NSNotification) {
let info = notification.userInfo!
let rect: CGRect = info[UIResponder.keyboardFrameBeginUserInfoKey] as! CGRect
let kbSize = rect.size
let insets = UIEdgeInsets(top: 0, left: 0, bottom: kbSize.height+20, right: 0)
self.scrolView.contentInset = insets
self.scrolView.scrollIndicatorInsets = insets
var visibleRect: CGRect = self.scrolView.convert(self.scrolView.bounds, to: self.view)
visibleRect.size.height -= rect.size.height;
let inputRect: CGRect = self.activeTextField.convert(self.activeTextField.bounds, to: self.scrolView)
if (visibleRect.contains(inputRect)) {
self.scrolView.scrollRectToVisible(inputRect, animated: true)
}
}
#objc func onKeyboardDisappear(_ notification: NSNotification) {
self.scrolView.contentInset = UIEdgeInsets.zero
self.scrolView.scrollIndicatorInsets = UIEdgeInsets.zero
}
public func textFieldDidBeginEditing(_ textField: UITextField) {
activeTextField = textField
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
activeTextField.resignFirstResponder()
return true
}
}
initially i dont want scrolling, and if i return keyboard i need textfield come to its original position and no scrolling again.
Only keyboard appears then only i need scrolling. please help me in the code.
You just need to set the contentOffset of your ScrollView right after the keyboard is hidden.
Create a variable to store offsetBeforeShowKeyboard
var offsetBeforeShowKeyboard: CGFloat?
When view is initially loaded:
self.scrollView.isScrollEnabled = false
When select any TextField:
public func textFieldDidBeginEditing(_ textField: UITextField) {
self.scrollView.isScrollEnabled = true
if (self.offsetBeforeShowKeyboard == nil) {
self.offsetBeforeShowKeyboard = self.scrollView.contentOffset
}
}
When keyboard is hidden
#objc func onKeyboardDisappear(_ notification: NSNotification) {
self.scrollView.isScrollEnabled = false
if let offset = self.offsetBeforeShowKeyboard {
self.scrolView.setContentOffset(offset, animated: true)
}
self.offsetBeforeShowKeyboard = nil
}
In viewWillAppear
yourScrollview.isScrollEnabled = false
After Keyboard appears make it true
yourScrollview.isScrollEnabled = true
Alternatively you can use IQKeyboard manager to take care of textfields.Checkout: IQKeyboardManager

textFieldShouldReturn not being called after upgrade in Swift 4

I have a view controller with a few UITextFields on it. When a UITextField has focus, if I tap on the Return key on the keyboard, I go to the next UITextField. If the next UITextField is below the keyboard, I move the view up.
All was fine until yesterday when I upgraded the app to Swift 4, after a few changes. Now it's no longer working. I loaded the Swift 3 version and it's working just fine. The problem is I don't see any difference and I can't figure it out.
class ServerWizardVC: UIViewController, UITextViewDelegate, UIDocumentMenuDelegate, UIDocumentPickerDelegate, FileManagerDelegate
#IBOutlet weak var tfServerURL: UITextField!
#IBOutlet weak var tfServerUser: UITextField!
#IBOutlet weak var tfServerPassword: UITextField!
#IBOutlet weak var tfServerPort: UITextField!
override func viewDidLoad()
{
print("ServerWizardVC > viewDidLoad")
super.viewDidLoad()
tfServerURL.tag = 0
registerForKeyboardNotifications()
deregisterFromKeyboardNotifications()
}
override func viewWillAppear(_ animated: Bool)
{
print("ServerWizardVC > viewWillAppear")
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
}
func registerForKeyboardNotifications()
{
print("ServerWizardVC > registerForKeyboardNotifications")
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWasShown), name: NSNotification.Name.UIKeyboardDidShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillBeHidden), name: NSNotification.Name.UIKeyboardDidShow, object: nil)
}
func deregisterFromKeyboardNotifications()
{
print("ServerWizardVC > deregisterFromKeyboardNotifications")
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillHide, object: nil)
}
#objc func keyboardWillShow(notification:NSNotification)
{
print("ServerWizardVC > keyboardWillShow")
let userInfo:NSDictionary = notification.userInfo! as NSDictionary
let keyboardFrame:NSValue = userInfo.value(forKey: UIKeyboardFrameEndUserInfoKey) as! NSValue
let keyboardRectangle = keyboardFrame.cgRectValue
let keyboardHeight = keyboardRectangle.height
keyboardHeightValue = keyboardHeight
}
#objc func keyboardWasShown(notification: NSNotification)
{
print("ServerWizardVC > keyboardWasShown")
}
#objc func keyboardWillBeHidden (notification: NSNotification)
{
print("ServerWizardVC > keyboardWillBeHidden")
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool
{
print("ServerWizardVC > textFieldShouldReturn")
if let nextField = tfServerURL.superview?.viewWithTag(textField.tag + 1) as? UITextField
{
nextField.becomeFirstResponder()
checkTextFieldPosition(tfTag: textField.tag + 1)
}
else
{
vMainView.frame.origin.y = 0
textField.resignFirstResponder()
}
return false
}
func checkTextFieldPosition(tfTag : Int)
{
print("ServerWizardVC > checkTextFieldPosition")
let keyboardTop = mainViewHeight - keyboardHeightValue
let tfServerPasswordTop = tfServerPassword.frame.origin.y
if(tfTag == 3)
{
if((keyboardTop < tfServerPasswordTop) && (vMainView.frame.origin.y == 0))
{
let yPosition = vMainView.frame.origin.y - keyboardHeightValue + 100
vMainView.frame.origin.y = yPosition
}
}
}
The reason I blame this on the Swift 4 upgrade is that I didn't even touch this class and everything else works fine.
Is there anything I'm missing?
textFieldShouldReturn is a UITextFieldDelegate function, but your class conforms to UITextViewDelegate instead. Replace the conformance with UITextFieldDelegate:
class ServerWizardVC: UIViewController, UITextFieldDelegate, UIDocumentMenuDelegate, UIDocumentPickerDelegate, FileManagerDelegate

Move view when a specific textfield is selected swift

I am created a meme generator app to better learn Swift and Xcode. I am learning to move the view when the user interacts with a text field that would be obstructed by the keyboard. I have this functionality working, with one exception. The desired functionality is to have the view slide up when the user is entering text for the bottom textfield, bot the top. The view slides up regardless of the text field the user is interacting with.
How can I assign this functionality only to the bottom text field? Here is my source code:
import UIKit
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextFieldDelegate {
#IBOutlet weak var imagePickerView: UIImageView!
#IBOutlet weak var cameraButton: UIBarButtonItem!
#IBOutlet weak var topText: UITextField!
#IBOutlet weak var bottomText: UITextField!
let memeTextAttributes:[String:Any] = [
NSAttributedStringKey.strokeColor.rawValue: UIColor.black,
NSAttributedStringKey.foregroundColor.rawValue: UIColor.white,
NSAttributedStringKey.font.rawValue: UIFont(name: "HelveticaNeue-CondensedBlack", size: 30)!,
NSAttributedStringKey.strokeWidth.rawValue: -5.0]
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
subscribeToKeyboardNotifications()
}
override func viewDidLoad() {
super.viewDidLoad()
// Diable camer a button if camera ource isn't available
cameraButton.isEnabled = UIImagePickerController.isSourceTypeAvailable(.camera)
topText.delegate = self
bottomText.delegate = self
topText.textAlignment = .center
bottomText.textAlignment = .center
topText.defaultTextAttributes = memeTextAttributes
bottomText.defaultTextAttributes = memeTextAttributes
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
unsubscribeFromKeyboardNotifications()
}
// MARK: Delegate Methods
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
imagePickerView.image = image
self.dismiss(animated: true, completion: nil)
}
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
self.dismiss(animated: true, completion: nil)
}
func textFieldDidBeginEditing(_ textField: UITextField) {
textField.text = ""
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
self.topText.resignFirstResponder()
self.bottomText.resignFirstResponder()
return true
}
// MARK: Move the keyboard up when the bottom textfield is tapped
#objc func keyboardWillShow(_ notification:Notification) {
view.frame.origin.y = 0 - getKeyboardHeight(notification)
}
func getKeyboardHeight(_ notification:Notification) -> CGFloat {
let userInfo = notification.userInfo
let keyboardSize = userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue // of CGRect
return keyboardSize.cgRectValue.height
}
func subscribeToKeyboardNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: .UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: .UIKeyboardWillHide, object: nil)
}
func unsubscribeFromKeyboardNotifications() {
NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillShow, object: nil)
NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillHide, object: nil)
}
// MARK: Move view down when keyboard is dismissed
#objc func keyboardWillHide(_ notification: Notification) {
view.frame.origin.y = 0
}
// MARK: IBActions
#IBAction func pickAnImageFromAlbum(_ sender: Any) {
let pickerController = UIImagePickerController()
pickerController.delegate = self
pickerController.sourceType = .photoLibrary
present(pickerController, animated: true, completion: nil)
}
#IBAction func pickAnImageFromCamera(_ sender: Any) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .camera
present(imagePicker, animated: true, completion: nil)
}
}
You can simply try this
//make a global textField to keep reference
var currentTappedTextField : UITextField?
//use this method to get tapped textField
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
currentTappedTextField = textField
return true
}
// now move view only when textfield is bottom
#objc func keyboardWillShow(_ notification:Notification) {
if(currentTappedTextField == bottomText){
view.frame.origin.y = 0 - getKeyboardHeight(notification)
}
}
Add view in scrollview.
Use
pod 'IQKeyboardManagerSwift'
It will automatically handle that. In app delegate write this code :
IQKeyboardManager.sharedManager().enable = true
IQKeyboardManager.sharedManager().keyboardDistanceFromTextField = 30.0
If you want for one textfield:
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
if textField == toptextField {
IQKeyboardManager.sharedManager().enable = false
}
else {
IQKeyboardManager.sharedManager().enable = true
}
return true
}
Approach without using external framework:
Use a bottom constraint from the text field to the parent view.
Adjust the constant value based on whether the keyboard is shown or hidden.
Steps:
Create a bottom constraint from your text field to the parent view.
Set the constraint's constant to an initial desired value
Add store the constraint as a property in the view controller
Observe UIKeyboardDidShow notification and get the end frame of the keyboard. Use the negative height of the end frame as the bottom constraint's constant.
Similarly do the same in UIKeyboardWillHide and set the bottom constraint constant to the original constant value
You just need to observe Keyboard Notification in your viewDidLoad :
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self,
selector: #selector(keyboardWillShow(_:)),
name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(keyboardWillHide),
name: NSNotification.Name.UIKeyboardWillHide, object: nil)
}
deinit {
NotificationCenter.default.removeObserver(self)
}
And declare selector methods to change your view constraint :
#objc
func keyboardWillShow(_ notification: Notification) {
if let keyboardHeight = notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue {
yourViewBottomConstraint.constant = keyboardHeight.cgRectValue.height + constantHeight
UIView.animate(withDuration: 0.25, animations: {
self.view.layoutIfNeeded()
})
}
}
#objc
func keyboardWillHide() {
yourViewBottomConstraint.constant = constantHeight
UIView.animate(withDuration: 0.25, animations: {
self.view.layoutIfNeeded()
})
}
Just don't forget to implement UITextFieldDelegate :
extension ViewController: UITextFieldDelegate {
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
self.view.endEditing(true)
return false
}
}

UIView container disappears when I move it's Y origin down

I have UIView which is container for button "send" and textView.
When I starting editing I have keyboard on the screen and I change Y origin of the container to move it higher and not be covered by keyboard.
When I finish editing I got keyboard hidden and my container(UIView with button and textView) just disappears! But if I turn simulator right or left this became visible again.
Here is the animation code that move my container up and down:
func textViewDidChange(textView: UITextView) {
self.messagePromptLabel.hidden = messageTextView.hasText() ? true : false
}
func textViewDidEndEditing(textView: UITextView) {
if !self.messageTextView.hasText() {
self.messagePromptLabel.hidden = false
}
}
func didTapScrollView(){
self.view.endEditing(true)
}
func keyboardWasShown(notification: NSNotification) {
let dict: NSDictionary = notification.userInfo!
let keyboardSize: NSValue = dict.valueForKey(UIKeyboardFrameEndUserInfoKey) as! NSValue
let frameKeyboardSize: CGRect = keyboardSize.CGRectValue()
UIView.animateWithDuration(0.3, animations: { () -> Void in
self.chatScrollView.frame.origin.y -= frameKeyboardSize.height
self.messageView.frame.origin.y -= frameKeyboardSize.height
}) { (finished: Bool) -> Void in
}
}
func keyboardWillHide(notification: NSNotification) {
UIView.animateWithDuration(0.3, animations: { () -> Void in
self.chatScrollView.frame.origin.y = self.chatScrollViewOriginY!
self.messageView.frame.origin.y = self.messageTextViewOriginY!
}) { (finished: Bool) -> Void in
}
}
Some additional code
This code may help find out something.
#IBOutlet weak var messageTextView: UITextView!
#IBOutlet weak var chatScrollView: UIScrollView!
#IBOutlet weak var messagePromptLabel: UILabel!
#IBOutlet weak var messageView: UIView!
var chatScrollViewOriginY: CGFloat?
var messageTextViewOriginY: CGFloat?
var messageArray = [String]()
var senderArray = [String]()
var currentUserImage: UIImage?
var recipientImage: UIImage?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
messageTextView.addSubview(messagePromptLabel)
self.title = recipientNickname
chatScrollViewOriginY = self.chatScrollView.frame.origin.y
messageTextViewOriginY = self.messageTextView.frame.origin.y
print(" messageTextViewOriginY \(messageTextViewOriginY)")
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWasShown:", name: UIKeyboardDidShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHide:", name: UIKeyboardWillHideNotification, object: nil)
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: "didTapScrollView")
tapGestureRecognizer.numberOfTouchesRequired = 1
chatScrollView.addGestureRecognizer(tapGestureRecognizer)
chatScrollView.backgroundColor = UIColor.redColor()
}
func textViewDidChange(textView: UITextView) {
self.messagePromptLabel.hidden = messageTextView.hasText() ? true : false
}
func textViewDidEndEditing(textView: UITextView) {
if !self.messageTextView.hasText() {
self.messagePromptLabel.hidden = false
}
}
func didTapScrollView(){
self.view.endEditing(true)
}
Question:
What make my UIView container invisible all the time when I hidding keyboard and make it visible when I turn my phone left or right?
You need to add this code in your send button action:
self.view.endEditing(true)

UITextView scrollview not moving when keyboard is shown

My app structure currently is a navigation controller that leads to viewcontrollers with scrollview embedded in them. The textfields, textview, buttons etc are on top of the scrollview. By using my current code, the scrollview moves the view when UITextFields are clicked, but not UITextViews. I have tried to adopt Apple's recommended method and tweaked it for UITextViews.
Also, in the function keyboardWillBeShown, the part that checks if active textfield/textview in hidden by the keyboard and scrolls, seems to not make any difference at all.
Where have I gone wrong? Thanks
class unwellBasic: UIViewController, UITextViewDelegate,
UIScrollViewDelegate, UITextFieldDelegate {
#IBOutlet var scrollView: UIScrollView!
weak var activeTextView : UITextView?
weak var activeTextField : UITextField?
#IBOutlet var main: UITextView!
#IBOutlet var initials: UITextField!
#IBOutlet var maleButton: UIButton!
#IBOutlet var femaleButton: UIButton!
#IBOutlet var age: UITextField!
#IBOutlet var test: UITextField!
func registerForKeyboardNotifications() {
let notificationCenter = NSNotificationCenter.defaultCenter()
notificationCenter.addObserver(self,
selector: "keyboardWillBeShown:",
name: UIKeyboardWillShowNotification,
object: nil)
notificationCenter.addObserver(self,
selector: "keyboardWillBeHidden:",
name: UIKeyboardWillHideNotification,
object: nil)
}
#IBAction func back(sender: AnyObject) {
self.navigationController?.popViewControllerAnimated(true)
}
#IBAction func next(sender: AnyObject) {
self.performSegueWithIdentifier("bodySegue", sender: self)
}
func tapped() {
initials.resignFirstResponder()
main.resignFirstResponder()
age.resignFirstResponder()
test.resignFirstResponder()
self.activeTextView = nil
}
// Called when the UIKeyboardDidShowNotification is sent.
func keyboardWillBeShown(sender: NSNotification) {
let info: NSDictionary = sender.userInfo!
let value: NSValue = info.valueForKey(UIKeyboardFrameEndUserInfoKey) as! NSValue
let keyboardSize: CGSize = value.CGRectValue().size
let contentInsets: UIEdgeInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardSize.height, 0.0)
scrollView.contentInset = contentInsets
scrollView.scrollIndicatorInsets = contentInsets
// If active text field is hidden by keyboard, scroll it so it's visible
if self.activeTextView != nil {
var aRect: CGRect = self.view.frame
aRect.size.height -= keyboardSize.height
let activeTextViewRect: CGRect? = self.activeTextView!.frame
let activeTextViewOrigin: CGPoint? = activeTextViewRect?.origin
if (!CGRectContainsPoint(aRect, activeTextViewOrigin!)) {
scrollView.scrollRectToVisible(activeTextViewRect!, animated:true)
}
}
if self.activeTextField != nil {
var aRect: CGRect = self.view.frame
aRect.size.height -= keyboardSize.height
let activeTextViewRect: CGRect? = self.activeTextField!.frame
let activeTextViewOrigin: CGPoint? = activeTextViewRect?.origin
if (!CGRectContainsPoint(aRect, activeTextViewOrigin!)) {
scrollView.scrollRectToVisible(activeTextViewRect!, animated:true)
}
}
}
// Called when the UIKeyboardWillHideNotification is sent
func keyboardWillBeHidden(sender: NSNotification) {
let contentInsets: UIEdgeInsets = UIEdgeInsetsMake(0.0, 0.0, 0.0, 0.0)
scrollView.contentInset = contentInsets
self.scrollView .setContentOffset(CGPointMake(0, 0), animated: true)
self .viewDidLayoutSubviews()
self.activeTextView = nil
}
func textViewDidBeginEditing(textView: UITextView) {
self.activeTextView = textView
scrollView.scrollEnabled = true
}
func textViewDidEndEditing(textView: UITextView) {
self.activeTextView = nil
scrollView.scrollEnabled = false
self.scrollView .setContentOffset(CGPointMake(0, 0), animated: true)
self .viewDidLayoutSubviews()
}
func textFieldDidBeginEditing(textField: UITextField) {
activeTextField = textField
scrollView.scrollEnabled = true
}
func textFieldDidEndEditing(textField: UITextField) {
activeTextField = nil
scrollView.scrollEnabled = false
}
func textFieldShouldReturn(textField: UITextField) -> Bool // called when 'return' key pressed. return NO to ignore.
{
textField.resignFirstResponder()
return true;
}
override func viewDidLoad() {
super.viewDidLoad()
var tap = UITapGestureRecognizer (target: self, action: ("tapped"))
self.view.addGestureRecognizer(tap)
self.main.delegate = self
self.initials.delegate = self
self.age.delegate = self
self.registerForKeyboardNotifications()
}
inherit your scroll view with TPKeyboardAvoiding, you don't need to code too much

Resources