Guest User

Untitled

a guest
Feb 7th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. class ServerWizardVC: UIViewController, UITextViewDelegate, UIDocumentMenuDelegate, UIDocumentPickerDelegate, FileManagerDelegate
  2.  
  3. @IBOutlet weak var tfServerURL: UITextField!
  4. @IBOutlet weak var tfServerUser: UITextField!
  5. @IBOutlet weak var tfServerPassword: UITextField!
  6. @IBOutlet weak var tfServerPort: UITextField!
  7.  
  8. override func viewDidLoad()
  9. {
  10. print("ServerWizardVC > viewDidLoad")
  11.  
  12. super.viewDidLoad()
  13.  
  14. tfServerURL.tag = 0
  15.  
  16. registerForKeyboardNotifications()
  17. deregisterFromKeyboardNotifications()
  18. }
  19.  
  20. override func viewWillAppear(_ animated: Bool)
  21. {
  22. print("ServerWizardVC > viewWillAppear")
  23.  
  24. NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
  25. }
  26.  
  27. func registerForKeyboardNotifications()
  28. {
  29. print("ServerWizardVC > registerForKeyboardNotifications")
  30.  
  31. NotificationCenter.default.addObserver(self, selector: #selector(keyboardWasShown), name: NSNotification.Name.UIKeyboardDidShow, object: nil)
  32. NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillBeHidden), name: NSNotification.Name.UIKeyboardDidShow, object: nil)
  33. }
  34.  
  35. func deregisterFromKeyboardNotifications()
  36. {
  37. print("ServerWizardVC > deregisterFromKeyboardNotifications")
  38.  
  39. NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillShow, object: nil)
  40. NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillHide, object: nil)
  41. }
  42.  
  43. @objc func keyboardWillShow(notification:NSNotification)
  44. {
  45. print("ServerWizardVC > keyboardWillShow")
  46.  
  47. let userInfo:NSDictionary = notification.userInfo! as NSDictionary
  48. let keyboardFrame:NSValue = userInfo.value(forKey: UIKeyboardFrameEndUserInfoKey) as! NSValue
  49. let keyboardRectangle = keyboardFrame.cgRectValue
  50. let keyboardHeight = keyboardRectangle.height
  51.  
  52. keyboardHeightValue = keyboardHeight
  53. }
  54.  
  55. @objc func keyboardWasShown(notification: NSNotification)
  56. {
  57. print("ServerWizardVC > keyboardWasShown")
  58. }
  59.  
  60. @objc func keyboardWillBeHidden (notification: NSNotification)
  61. {
  62. print("ServerWizardVC > keyboardWillBeHidden")
  63. }
  64.  
  65. func textFieldShouldReturn(_ textField: UITextField) -> Bool
  66. {
  67. print("ServerWizardVC > textFieldShouldReturn")
  68.  
  69. if let nextField = tfServerURL.superview?.viewWithTag(textField.tag + 1) as? UITextField
  70. {
  71. nextField.becomeFirstResponder()
  72.  
  73. checkTextFieldPosition(tfTag: textField.tag + 1)
  74. }
  75. else
  76. {
  77. vMainView.frame.origin.y = 0
  78.  
  79. textField.resignFirstResponder()
  80. }
  81.  
  82. return false
  83. }
  84.  
  85. func checkTextFieldPosition(tfTag : Int)
  86. {
  87. print("ServerWizardVC > checkTextFieldPosition")
  88.  
  89. let keyboardTop = mainViewHeight - keyboardHeightValue
  90. let tfServerPasswordTop = tfServerPassword.frame.origin.y
  91.  
  92. if(tfTag == 3)
  93. {
  94. if((keyboardTop < tfServerPasswordTop) && (vMainView.frame.origin.y == 0))
  95. {
  96. let yPosition = vMainView.frame.origin.y - keyboardHeightValue + 100
  97. vMainView.frame.origin.y = yPosition
  98. }
  99. }
  100. }
  101.  
  102. class ServerWizardVC: UIViewController, UITextFieldDelegate, UIDocumentMenuDelegate, UIDocumentPickerDelegate, FileManagerDelegate
Add Comment
Please, Sign In to add comment