소스 검색

键盘优化

南鑫林 5 년 전
부모
커밋
6382aee2df
1개의 변경된 파일13개의 추가작업 그리고 16개의 파일을 삭제
  1. 13 16
      RainbowPlanet/RainbowPlanet/Tools/CommentInputView/CommentInputView.swift

+ 13 - 16
RainbowPlanet/RainbowPlanet/Tools/CommentInputView/CommentInputView.swift

@@ -25,8 +25,9 @@ class CommentInputView: UIView {
             
             
         }
         }
     }
     }
+    /// 添加视图的高度
+    var screenHeight : CGFloat = 0
     
     
-
     
     
     typealias CommentInputViewClosure = (String) -> ()
     typealias CommentInputViewClosure = (String) -> ()
     var commentInputViewClosure :CommentInputViewClosure?
     var commentInputViewClosure :CommentInputViewClosure?
@@ -40,19 +41,15 @@ class CommentInputView: UIView {
     }
     }
 
 
     /// 初始化是否隐藏
     /// 初始化是否隐藏
-    init(isHidden:Bool,height:CGFloat = 0) {
+    init(isHidden:Bool,height:CGFloat = kScreenHeight) {
         self.init()
         self.init()
         inputViewIsHidden = isHidden
         inputViewIsHidden = isHidden
-        if height == 0 {
-            if isHidden {
-                self.frame = CGRect(x: 0, y: kScreenHeight, width: kScreenWidth, height: kSafeTabBarHeight+48)
-            } else {
-                self.frame = CGRect(x: 0, y: kScreenHeight-kSafeTabBarHeight-48, width: kScreenWidth, height: kSafeTabBarHeight+48)
-            }
-        }else {
-            self.frame = CGRect(x: 0, y: height-kSafeTabBarHeight-48, width: kScreenWidth, height: kSafeTabBarHeight+48)
+        screenHeight = height
+        if isHidden {
+            self.frame = CGRect(x: 0, y: screenHeight, width: kScreenWidth, height: kSafeTabBarHeight+48)
+        } else {
+            self.frame = CGRect(x: 0, y: screenHeight-kSafeTabBarHeight-48, width: kScreenWidth, height: kSafeTabBarHeight+48)
         }
         }
-        
         setupViews()
         setupViews()
         setupData()
         setupData()
     }
     }
@@ -111,7 +108,7 @@ class CommentInputView: UIView {
                     self?.sendButton.isEnabled = false
                     self?.sendButton.isEnabled = false
                 }
                 }
                 UIView.animate(withDuration: duration ?? 0, animations: {
                 UIView.animate(withDuration: duration ?? 0, animations: {
-                    self?.y = kScreenHeight - (keyboardFrame?.size.height)! - (self?.height)! + kSafeTabBarHeight
+                    self?.y = (self?.screenHeight)! - (keyboardFrame?.size.height)! - (self?.height)! + kSafeTabBarHeight
                 })
                 })
             })
             })
         
         
@@ -135,9 +132,9 @@ class CommentInputView: UIView {
                 }
                 }
                 UIView.animate(withDuration: duration ?? 0, animations: {
                 UIView.animate(withDuration: duration ?? 0, animations: {
                     if self?.inputViewIsHidden ?? true {
                     if self?.inputViewIsHidden ?? true {
-                        self?.y = kScreenHeight
+                        self?.y = (self?.screenHeight)!
                     }else {
                     }else {
-                        self?.y = kScreenHeight - (self?.height)!
+                        self?.y = (self?.screenHeight)! - (self?.height)!
                         
                         
                     }
                     }
                 })
                 })
@@ -156,7 +153,7 @@ class CommentInputView: UIView {
         self.inputTextView.text = ""
         self.inputTextView.text = ""
         self.inputTextView.height = 30
         self.inputTextView.height = 30
         self.height = 48 + kSafeTabBarHeight
         self.height = 48 + kSafeTabBarHeight
-        self.y = kScreenHeight - self.height
+        self.y = screenHeight - self.height
         self.endEditing(true)
         self.endEditing(true)
     }
     }
     
     
@@ -180,6 +177,6 @@ extension CommentInputView : UITextViewDelegate {
             textView.height = 30
             textView.height = 30
         }
         }
         self.height = (self.inputTextView.height) + kSafeTabBarHeight + 20
         self.height = (self.inputTextView.height) + kSafeTabBarHeight + 20
-        self.y = kScreenHeight - (self.keyboardH) - (self.inputTextView.height) - 20
+        self.y = screenHeight - (self.keyboardH) - (self.inputTextView.height) - 20
     }
     }
 }
 }