Browse Source

原生输入法问题处理

Chris 5 years ago
parent
commit
be2aad8e14

+ 20 - 8
RainbowPlanet/RainbowPlanet/Modules/MineModule/EditExpressAddress/View/EditExpressAddressTableViewCell.swift

@@ -83,14 +83,7 @@ class EditExpressAddressTableViewCell: UITableViewCell {
         editTextView.isScrollEnabled = false
         editTextView.textContainer.lineFragmentPadding = 0
         editTextView.textContainerInset = .zero
-        editTextView.rx.text.orEmpty.changed.subscribe(onNext: {
-            [weak self] (text) in
-            self?.editTextView.text = String(text.prefix(150)) as String
-            if let editTextViewClosure = self?.editTextViewClosure {
-                editTextViewClosure(self?.editTextView.text ?? "",(self?.indexPath!)!)
-            }
-            
-        }).disposed(by: disposeBag)
+        editTextView.delegate = self
         return editTextView
     }()
     
@@ -124,3 +117,22 @@ class EditExpressAddressTableViewCell: UITableViewCell {
     }
 
 }
+
+extension EditExpressAddressTableViewCell: UITextViewDelegate {
+    
+    func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
+        if textView == editTextView {
+            var fullStr = textView.text ?? ""
+            if textView.text?.count ?? 0 > 180 {
+                fullStr = String(fullStr.prefix(150)) as String
+                textView.text = fullStr
+            }
+            
+            if let editTextViewClosure = self.editTextViewClosure {
+                editTextViewClosure(self.editTextView.text ?? "",(self.indexPath!))
+            }
+        }
+        return true
+    }
+    
+}

+ 20 - 8
RainbowPlanet/RainbowPlanet/Modules/OrderModule/OrderApplyRefund/View/OrderApplyRefundNoteInfoCell.swift

@@ -78,15 +78,27 @@ class OrderApplyRefundNoteInfoCell: UITableViewCell {
         noteTextView.placeholder = "如需部分商品退款请备注退款商品的名称和数量,如订单疑问可通过“我的”联系社长哦"
         noteTextView.placeholderTextColor = k999999Color
         noteTextView.isScrollEnabled = false
-        noteTextView.rx.text.orEmpty.changed.subscribe(onNext: {
-            [weak self] (text) in
-            self?.noteTextView.text = String(text.prefix(150)) as String
-
-            if let noteTextViewClosure = self?.noteTextViewClosure {
-                noteTextViewClosure(self?.noteTextView.text ?? "")
-            }
-        }).disposed(by: disposeBag)
+        noteTextView.delegate = self
         return noteTextView
     }()
     
 }
+
+extension OrderApplyRefundNoteInfoCell: UITextViewDelegate {
+    
+    func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
+        if textView == noteTextView {
+            var fullStr = textView.text ?? ""
+            if textView.text?.count ?? 0 > 180 {
+                fullStr = String(fullStr.prefix(150)) as String
+                textView.text = fullStr
+            }
+            
+            if let noteTextViewClosure = self.noteTextViewClosure {
+                noteTextViewClosure(self.noteTextView.text ?? "")
+            }
+        }
+        return true
+    }
+    
+}

+ 20 - 7
RainbowPlanet/RainbowPlanet/Modules/OrderModule/OrderComment/View/OrderCommentTableViewCell.swift

@@ -160,13 +160,7 @@ class OrderCommentTableViewCell: UITableViewCell {
         cmtTextView.font = kRegularFont14
         cmtTextView.placeholder = "输入商品评价..."
         cmtTextView.placeholderTextColor = k999999Color
-        cmtTextView.rx.text.orEmpty.changed.subscribe(onNext: {
-            [weak self] (text) in
-            self?.cmtTextView.text = String(text.prefix(150)) as String
-            if let commentTextViewClosure = self?.commentTextViewClosure {
-                commentTextViewClosure(self?.cmtTextView.text ?? "")
-            }
-        }).disposed(by: disposeBag)
+        cmtTextView.delegate = self
         return cmtTextView
     }()
     
@@ -268,3 +262,22 @@ extension OrderCommentTableViewCell: UICollectionViewDelegateFlowLayout,UICollec
     }
     
 }
+
+extension OrderCommentTableViewCell: UITextViewDelegate {
+    
+    func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
+        if textView == cmtTextView {
+            var fullStr = textView.text ?? ""
+            if textView.text?.count ?? 0 > 180 {
+                fullStr = String(fullStr.prefix(150)) as String
+                textView.text = fullStr
+            }
+            
+            if let commentTextViewClosure = self.commentTextViewClosure {
+                commentTextViewClosure(self.cmtTextView.text ?? "")
+            }
+        }
+        return true
+    }
+    
+}

+ 20 - 8
RainbowPlanet/RainbowPlanet/Modules/OrderModule/OrderPayOrder/View/ShoppingCartPayOrderFooter.swift

@@ -99,14 +99,7 @@ class ShoppingCartPayOrderFooter: BaseView {
         msgTextField.clearButtonMode = .whileEditing
         msgTextField.sizeToFit()
         msgTextField.tintColor = kFFA42FColor
-        
-        msgTextField.rx.text.orEmpty.changed.subscribe(onNext: { [weak self] (text) in
-            self?.msgTextField.text = String(text.prefix(50)) as String
-            if let buyerNoteBlock = self?.buyerNoteBlock {
-                buyerNoteBlock(self?.msgTextField.text ?? "")
-            }
-            
-        }).disposed(by: disposeBag)
+        msgTextField.delegate = self
         return msgTextField
     }()
     
@@ -127,3 +120,22 @@ class ShoppingCartPayOrderFooter: BaseView {
     }()
     
 }
+
+extension ShoppingCartPayOrderFooter: UITextFieldDelegate {
+    
+    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
+        if textField == msgTextField {
+            var fullStr = textField.text ?? ""
+            if textField.text?.count ?? 0 > 80 {
+                fullStr = String(fullStr.prefix(50)) as String
+                textField.text = fullStr
+            }
+                        
+            if let buyerNoteBlock = self.buyerNoteBlock {
+                buyerNoteBlock(self.msgTextField.text ?? "")
+            }
+        }
+        return true
+    }
+    
+}