|
@@ -150,9 +150,7 @@ class TSPTPInputVC: TSBaseVC {
|
|
|
uploadView.upLoadImage = nil
|
|
|
}else{//添加
|
|
|
|
|
|
- if UserDefaults.standard.string(forKey: "isFirstUploadImagePTP") == nil {
|
|
|
- UserDefaults.standard.set("1", forKey: "isFirstUploadImagePTP")
|
|
|
- UserDefaults.standard.synchronize()
|
|
|
+ if TSPTPImageHintVC.isShowUploadImageHint{
|
|
|
presentModalHintVC()
|
|
|
}else {
|
|
|
pickSinglePhoto()
|
|
@@ -210,23 +208,17 @@ class TSPTPInputVC: TSBaseVC {
|
|
|
|
|
|
//###################################### 输入框 ######################################
|
|
|
private let maxLength = 200 // 最大长度限制
|
|
|
- lazy var customTextView: UITextField = {
|
|
|
- let customTextView = UITextField()
|
|
|
- customTextView.placeholder = "Please describe your photo".localized
|
|
|
- customTextView.font = .font(size: 14)
|
|
|
- customTextView.textColor = .white
|
|
|
+ lazy var customTextView: TSPlaceholderTextView = {
|
|
|
+ let customTextView = TSPlaceholderTextView(
|
|
|
+ placeholder: "Please describe your photo".localized,
|
|
|
+ text: "",
|
|
|
+ font: .font(size: 14),
|
|
|
+ textColor: .white,
|
|
|
+ backgroundColor: .clear
|
|
|
+ )
|
|
|
+ customTextView.verticalAlignment = .center
|
|
|
customTextView.delegate = self
|
|
|
customTextView.returnKeyType = .send
|
|
|
-// customTextView.iq.distanceFromKeyboard = 0
|
|
|
-
|
|
|
- customTextView.attributedPlaceholder = NSAttributedString(
|
|
|
- string: "Please describe your photo".localized,
|
|
|
- attributes: [
|
|
|
- .foregroundColor: UIColor.white.withAlphaComponent(0.4),
|
|
|
- .font: UIFont.font(size: 14)
|
|
|
- ]
|
|
|
- )
|
|
|
-
|
|
|
return customTextView
|
|
|
}()
|
|
|
|
|
@@ -259,6 +251,7 @@ class TSPTPInputVC: TSBaseVC {
|
|
|
|
|
|
customTextView.snp.makeConstraints { make in
|
|
|
make.top.bottom.equalTo(0)
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
make.leading.equalTo(12.0)
|
|
|
make.trailing.equalTo(-32)
|
|
|
}
|
|
@@ -278,6 +271,14 @@ class TSPTPInputVC: TSBaseVC {
|
|
|
let cp = TSCollectionViewComponent(frame: CGRect.zero, layout: layout, attributes: [:])
|
|
|
cp.collectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: collectionViewBtootm, right: 0)
|
|
|
|
|
|
+
|
|
|
+ // 禁用自动 contentInset 调整
|
|
|
+ if #available(iOS 11.0, *) {
|
|
|
+ cp.collectionView.contentInsetAdjustmentBehavior = .never
|
|
|
+ } else {
|
|
|
+ automaticallyAdjustsScrollViewInsets = false
|
|
|
+ }
|
|
|
+
|
|
|
cp.sectionActionHandler = { [weak self] cellCp, indexPath in
|
|
|
guard let self = self else { return }
|
|
|
if let cmd = cellCp as? String, cmd == "delete" {
|
|
@@ -332,9 +333,9 @@ class TSPTPInputVC: TSBaseVC {
|
|
|
}
|
|
|
|
|
|
|
|
|
-// let tapGesture = UITapGestureRecognizer(target: self, action: #selector(clickView))
|
|
|
-// tapGesture.cancelsTouchesInView = false
|
|
|
-// view.addGestureRecognizer(tapGesture)
|
|
|
+ let tapGesture = UITapGestureRecognizer(target: self, action: #selector(clickView))
|
|
|
+ tapGesture.cancelsTouchesInView = false
|
|
|
+ view.addGestureRecognizer(tapGesture)
|
|
|
|
|
|
collectionComponent.clear()
|
|
|
collectionComponent.reloadView(with:viewModel.colDataArray)
|
|
@@ -358,8 +359,8 @@ class TSPTPInputVC: TSBaseVC {
|
|
|
override func dealThings() {
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(vipInfoChanged), name: .kPurchaseDidChanged, object: nil)
|
|
|
updateVipView()
|
|
|
-
|
|
|
-// // 监听键盘事件
|
|
|
+ collectionViewObserverHandle()
|
|
|
+//// // 监听键盘事件
|
|
|
// NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
|
|
|
// NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
|
|
|
}
|
|
@@ -373,6 +374,32 @@ class TSPTPInputVC: TSBaseVC {
|
|
|
//
|
|
|
// IQKeyboardManager.shared.isEnabled = true
|
|
|
// }
|
|
|
+
|
|
|
+
|
|
|
+ private var collectionViewObserver: CollectionViewObserver!
|
|
|
+
|
|
|
+ func collectionViewObserverHandle(){
|
|
|
+ collectionViewObserver = CollectionViewObserver(collectionView: collectionComponent.collectionView)
|
|
|
+
|
|
|
+ collectionViewObserver.onContentSizeChange = { size in
|
|
|
+ print("collectionViewObserver 内容大小变化: \(size)")
|
|
|
+ }
|
|
|
+
|
|
|
+ collectionViewObserver.onContentInsetChange = { inset in
|
|
|
+ print("collectionViewObserver 内边距变化: \(inset)")
|
|
|
+ }
|
|
|
+
|
|
|
+ collectionViewObserver.onContentOffsetChange = { offset in
|
|
|
+ print("collectionViewObserver 偏移量变化: \(offset)")
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
|
|
+ print("contentOffset 变化: \(scrollView.contentOffset)")
|
|
|
+ // 实时监听偏移量变化
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
extension TSPTPInputVC {
|
|
@@ -380,19 +407,24 @@ extension TSPTPInputVC {
|
|
|
var cusStackViewH:CGFloat{
|
|
|
get {
|
|
|
if cusStackView.viewH > 0{
|
|
|
+ dePrint("collectionViewObserver cusStackView.viewH == \(cusStackView.viewH)")
|
|
|
return cusStackView.viewH
|
|
|
}
|
|
|
- return 551+bannerH+bannerY//+promptTextViewH
|
|
|
+ dePrint("collectionViewObserver cusStackView.viewH = \(462+bannerH+bannerY+promptTextViewH)")
|
|
|
+ return 462+bannerH+bannerY+promptTextViewH
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func upDateCusStackViewH(){
|
|
|
- self.collectionComponent.collectionView.contentInset = UIEdgeInsets(top: cusStackViewH, left: 0, bottom: collectionViewBtootm, right: 0)
|
|
|
+ let cusH = cusStackViewH
|
|
|
+ self.collectionComponent.collectionView.contentInset = UIEdgeInsets(top: cusH, left: 0, bottom: collectionViewBtootm, right: 0)
|
|
|
cusStackView.snp.remakeConstraints { make in
|
|
|
- make.top.equalTo(-cusStackViewH)
|
|
|
+ make.top.equalTo(-cusH)
|
|
|
make.leading.trailing.equalTo(0)
|
|
|
- make.height.equalTo(cusStackViewH)
|
|
|
+ make.height.equalTo(cusH)
|
|
|
}
|
|
|
+ self.collectionComponent.collectionView.contentOffset = CGPoint(x: 0, y: -cusH)
|
|
|
+
|
|
|
}
|
|
|
|
|
|
func presentModalHintVC(){
|
|
@@ -407,12 +439,6 @@ extension TSPTPInputVC {
|
|
|
|
|
|
collectionComponent.collectionView.addSubview(cusStackView)
|
|
|
|
|
|
-// cusStackView.addSubviewToStack(promptTextView)
|
|
|
-// promptTextView.snp.makeConstraints { make in
|
|
|
-// make.height.equalTo(promptTextViewH)
|
|
|
-// make.width.equalTo(k_ScreenWidth)
|
|
|
-// }
|
|
|
-
|
|
|
cusStackView.addSubviewToStack(entranceView)
|
|
|
entranceView.snp.makeConstraints { make in
|
|
|
make.height.equalTo(bannerH+bannerY)
|
|
@@ -458,55 +484,31 @@ extension TSPTPInputVC {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+// cusStackView.addSubviewToStack(promptTextView)
|
|
|
+// promptTextView.snp.makeConstraints { make in
|
|
|
+// make.height.equalTo(promptTextViewH)
|
|
|
+// make.width.equalTo(k_ScreenWidth)
|
|
|
+// }
|
|
|
+ }
|
|
|
+
|
|
|
+ override func viewDidLayoutSubviews() {
|
|
|
+ super.viewDidLayoutSubviews()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-extension TSPTPInputVC: UITextFieldDelegate{
|
|
|
- // MARK: - UITextFieldDelegate
|
|
|
- func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
|
|
- if textField.returnKeyType == .send {
|
|
|
- textField.resignFirstResponder() // 可选:收起键盘
|
|
|
-
|
|
|
- // 触发发送逻辑
|
|
|
-
|
|
|
-
|
|
|
- return true
|
|
|
- }
|
|
|
- return false
|
|
|
- }
|
|
|
-
|
|
|
- func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
|
|
|
- // 获取当前文本
|
|
|
- guard let currentText = textField.text else {
|
|
|
- return true
|
|
|
- }
|
|
|
-
|
|
|
- clearBtn.isHidden = currentText.count <= 0
|
|
|
-
|
|
|
- // 计算新文本
|
|
|
- let newText = (currentText as NSString).replacingCharacters(in: range, with: string)
|
|
|
+extension TSPTPInputVC: UITextViewDelegate{
|
|
|
+ // 实现 UITextViewDelegate 协议方法,控制 return 键行为
|
|
|
+ func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
|
|
|
|
|
|
- // 如果新文本长度 > maxLength,截断并返回 false
|
|
|
- if newText.count > maxLength {
|
|
|
- textField.text = String(newText.prefix(maxLength))
|
|
|
+ if text == "\n" {
|
|
|
+ // 当输入为换行符(即按下 return 键)时,执行相应操作
|
|
|
+ //sendBolck?(textView.text)
|
|
|
return false
|
|
|
}
|
|
|
-
|
|
|
return true
|
|
|
}
|
|
|
-
|
|
|
- func textFieldDidBeginEditing(_ textField: UITextField) {
|
|
|
- print("输入框开始编辑 - 被点击了")
|
|
|
- // 在这里可以通知控制器滚动到合适位置
|
|
|
-
|
|
|
-// DispatchQueue.main.async {
|
|
|
-// let rect = self.promptTextView.convert(self.promptTextView.bounds, to: self.collectionComponent.collectionView)
|
|
|
-// self.collectionComponent.collectionView.scrollRectToVisible(rect, animated: true)
|
|
|
-// }
|
|
|
- }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -598,13 +600,13 @@ extension TSPTPInputVC {
|
|
|
}
|
|
|
// dePrint("keyboardWillShow contentInset IQKeyboardManager=\(IQKeyboardManager.shared.isEnabled)")
|
|
|
|
|
|
- let keyboardHeight = keyboardFrame.height
|
|
|
- let contentInset = UIEdgeInsets(top:cusStackViewH, left: 0, bottom: keyboardHeight, right: 0)
|
|
|
- dePrint("keyboardWillShow contentInset=\(contentInset)")
|
|
|
-// UIView.animate(withDuration: animationDuration) {
|
|
|
- self.collectionComponent.collectionView.contentInset = contentInset
|
|
|
- self.collectionComponent.collectionView.scrollIndicatorInsets = contentInset
|
|
|
-// }
|
|
|
+// let keyboardHeight = keyboardFrame.height
|
|
|
+// let contentInset = UIEdgeInsets(top:cusStackViewH, left: 0, bottom: keyboardHeight, right: 0)
|
|
|
+// dePrint("keyboardWillShow contentInset=\(contentInset)")
|
|
|
+//// UIView.animate(withDuration: animationDuration) {
|
|
|
+// self.collectionComponent.collectionView.contentInset = contentInset
|
|
|
+// self.collectionComponent.collectionView.scrollIndicatorInsets = contentInset
|
|
|
+//// }
|
|
|
|
|
|
// kDelayMainShort {
|
|
|
// self.collectionComponent.collectionView.scrollToLastItem(animated: false)
|
|
@@ -616,12 +618,12 @@ extension TSPTPInputVC {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- let contentInset = UIEdgeInsets(top: cusStackViewH, left: 0, bottom: collectionViewBtootm, right: 0)
|
|
|
- dePrint("keyboardWillHide contentInset=\(contentInset)")
|
|
|
-// UIView.animate(withDuration: animationDuration) {
|
|
|
- self.collectionComponent.collectionView.contentInset = contentInset
|
|
|
- self.collectionComponent.collectionView.scrollIndicatorInsets = contentInset
|
|
|
-// }
|
|
|
+// let contentInset = UIEdgeInsets(top: cusStackViewH, left: 0, bottom: collectionViewBtootm, right: 0)
|
|
|
+// dePrint("keyboardWillHide contentInset=\(contentInset)")
|
|
|
+//// UIView.animate(withDuration: animationDuration) {
|
|
|
+// self.collectionComponent.collectionView.contentInset = contentInset
|
|
|
+// self.collectionComponent.collectionView.scrollIndicatorInsets = contentInset
|
|
|
+//// }
|
|
|
}
|
|
|
|
|
|
|