Browse Source

text file

Marino Faggiana 7 years ago
parent
commit
6ac1e6ffa7
2 changed files with 27 additions and 3 deletions
  1. 1 0
      iOSClient/Text/NCText.storyboard
  2. 26 3
      iOSClient/Text/NCText.swift

+ 1 - 0
iOSClient/Text/NCText.storyboard

@@ -51,6 +51,7 @@
                         </barButtonItem>
                     </navigationItem>
                     <connections>
+                        <outlet property="bottomConstraint" destination="KKy-aG-Q0G" id="Vl0-1L-h0O"/>
                         <outlet property="cancelButton" destination="brk-EO-iNZ" id="8gM-f2-AtV"/>
                         <outlet property="nextButton" destination="Hyb-2c-5Hb" id="Zmo-Th-UUq"/>
                         <outlet property="textView" destination="pmg-g2-Fbs" id="T5E-gh-UZ6"/>

+ 26 - 3
iOSClient/Text/NCText.swift

@@ -14,6 +14,8 @@ class NCText: UIViewController, UITextViewDelegate {
     @IBOutlet weak var nextButton: UIBarButtonItem!
     @IBOutlet weak var textView: UITextView!
     
+    @IBOutlet weak var bottomConstraint: NSLayoutConstraint!
+    
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
     
     var metadata: tableMetadata?
@@ -23,6 +25,9 @@ class NCText: UIViewController, UITextViewDelegate {
         
         super.viewDidLoad()
         
+        NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillShowHandle(info:)), name: .UIKeyboardWillShow, object: nil)
+        NotificationCenter.default.addObserver(self, selector:#selector(self.keyboardWillHideHandle), name: .UIKeyboardWillHide, object: nil)
+
         self.navigationController?.navigationBar.topItem?.title = NSLocalizedString("_title_new_text_file_", comment: "")
         self.navigationController?.navigationBar.barTintColor = NCBrandColor.sharedInstance.brand
         self.navigationController?.navigationBar.tintColor = NCBrandColor.sharedInstance.navigationBarText
@@ -43,6 +48,10 @@ class NCText: UIViewController, UITextViewDelegate {
             textView.text = loadText
             nextButton.title = NSLocalizedString("_save_", comment: "")
             self.navigationController?.navigationBar.topItem?.title = NSLocalizedString(metadata.fileNamePrint, comment: "")
+            
+        } else {
+            
+            loadText = ""
         }
         
         textView.isUserInteractionEnabled = true
@@ -52,9 +61,23 @@ class NCText: UIViewController, UITextViewDelegate {
         textViewDidChange(textView)
     }
 
-    override func viewWillAppear(_ animated: Bool) {
-
-        super.viewWillAppear(animated)
+    func keyboardWillShowHandle(info:NSNotification) {
+        
+        let frameView = self.view.convert(self.view.bounds, to: self.view.window)
+        let endView = frameView.origin.y + frameView.size.height
+        
+        if let keyboardSize = (info.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue, let _ = self.view.window?.frame {
+            
+            if endView - keyboardSize.origin.y > 0 {
+                bottomConstraint.constant = endView - keyboardSize.origin.y
+            } else {
+                bottomConstraint.constant = 0
+            }
+        }
+    }
+    
+    func keyboardWillHideHandle() {
+        bottomConstraint.constant = 0
     }
     
     func textViewDidChange(_ textView: UITextView) {