|
@@ -23,7 +23,7 @@ class TSPTPInputVC: TSBaseVC {
|
|
|
return photoPickerManager
|
|
|
}()
|
|
|
|
|
|
-
|
|
|
+ private var keyboardHeight: CGFloat = 0
|
|
|
var hintBaseVC = TSAIListHintBaseVC(config: .defaultConfig)
|
|
|
|
|
|
//###################################### 导航栏 view ######################################
|
|
@@ -118,7 +118,6 @@ class TSPTPInputVC: TSBaseVC {
|
|
|
|
|
|
|
|
|
//###################################### 输入框 ######################################
|
|
|
- private let maxLength = 200 // 最大长度限制
|
|
|
lazy var customTextView: TSPlaceholderTextView = {
|
|
|
let customTextView = TSPlaceholderTextView(
|
|
|
placeholder: "Please describe your photo".localized,
|
|
@@ -127,14 +126,14 @@ class TSPTPInputVC: TSBaseVC {
|
|
|
textColor: .white,
|
|
|
backgroundColor: .clear
|
|
|
)
|
|
|
- customTextView.verticalAlignment = .center
|
|
|
customTextView.delegate = self
|
|
|
customTextView.returnKeyType = .send
|
|
|
return customTextView
|
|
|
}()
|
|
|
|
|
|
- lazy var clearBtn: UIButton = {
|
|
|
- let clearBtn = UIButton.createButton(
|
|
|
+ lazy var clearBtn: TSUIExpandedTouchButton = {
|
|
|
+ let clearBtn = TSUIExpandedTouchButton()
|
|
|
+ clearBtn.setUpButton(
|
|
|
image: UIImage(named: "clear_text")
|
|
|
)
|
|
|
{ [weak self] in
|
|
@@ -145,7 +144,7 @@ class TSPTPInputVC: TSBaseVC {
|
|
|
return clearBtn
|
|
|
}()
|
|
|
|
|
|
- var promptTextViewH:CGFloat = 84.0
|
|
|
+ var promptTextViewH:CGFloat = 96.0
|
|
|
lazy var promptTextView:UIView = {
|
|
|
let promptTextView = UIView()
|
|
|
promptTextView.clipsToBounds = true
|
|
@@ -161,10 +160,11 @@ class TSPTPInputVC: TSBaseVC {
|
|
|
bgView.addSubview(clearBtn)
|
|
|
|
|
|
customTextView.snp.makeConstraints { make in
|
|
|
- make.top.bottom.equalTo(0)
|
|
|
make.centerY.equalToSuperview()
|
|
|
make.leading.equalTo(12.0)
|
|
|
- make.trailing.equalTo(-32)
|
|
|
+ make.top.equalTo(12.0)
|
|
|
+ make.bottom.equalTo(-12.0)
|
|
|
+ make.trailing.equalTo(-20)
|
|
|
}
|
|
|
|
|
|
clearBtn.snp.makeConstraints { make in
|
|
@@ -216,7 +216,7 @@ class TSPTPInputVC: TSBaseVC {
|
|
|
kPresentModalVC(target: self, modelVC: browseVC,transitionStyle: .crossDissolve)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ cp.collectionView.keyboardDismissMode = .interactive
|
|
|
return cp
|
|
|
}()
|
|
|
|
|
@@ -272,46 +272,36 @@ class TSPTPInputVC: TSBaseVC {
|
|
|
updateVipView()
|
|
|
TSAIListHintBaseVC.userDefaultsKey = "isFirstUploadImagePTP"
|
|
|
// 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)
|
|
|
+// // 监听键盘事件
|
|
|
+ NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
|
|
|
+ NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+// private var collectionViewObserver: CollectionViewObserver!
|
|
|
//
|
|
|
-// override func viewWillAppear(_ animated: Bool) {
|
|
|
-// super.viewWillAppear(animated)
|
|
|
-// IQKeyboardManager.shared.isEnabled = false
|
|
|
-// }
|
|
|
-// override func viewWillDisappear(_ animated: Bool) {
|
|
|
-// super.viewWillDisappear(animated)
|
|
|
+// 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)")
|
|
|
+// }
|
|
|
//
|
|
|
-// 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)")
|
|
|
- // 实时监听偏移量变化
|
|
|
- }
|
|
|
+//
|
|
|
+//
|
|
|
+// func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
|
|
+// print("contentOffset 变化: \(scrollView.contentOffset)")
|
|
|
+// // 实时监听偏移量变化
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
extension TSPTPInputVC {
|
|
@@ -322,20 +312,29 @@ extension TSPTPInputVC {
|
|
|
dePrint("collectionViewObserver cusStackView.viewH == \(cusStackView.viewH)")
|
|
|
return cusStackView.viewH
|
|
|
}
|
|
|
- return 454 //+bannerH+bannerY+promptTextViewH
|
|
|
+ return 454 //promptTextViewH
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func upDateCusStackViewH(){
|
|
|
+ func upDateCusStackViewH(scrollTop:Bool = true){
|
|
|
let cusH = cusStackViewH
|
|
|
self.collectionComponent.collectionView.contentInset = UIEdgeInsets(top: cusH, left: 0, bottom: collectionViewBtootm, right: 0)
|
|
|
- cusStackView.snp.remakeConstraints { make in
|
|
|
+
|
|
|
+ cusStackView.snp.updateConstraints { make in
|
|
|
make.top.equalTo(-cusH)
|
|
|
- make.leading.trailing.equalTo(0)
|
|
|
make.height.equalTo(cusH)
|
|
|
}
|
|
|
- self.collectionComponent.collectionView.contentOffset = CGPoint(x: 0, y: -cusH)
|
|
|
|
|
|
+ dePrint("self.collectionComponent.collectionView.contentOffset.y=\(self.collectionComponent.collectionView.contentOffset.y)")
|
|
|
+
|
|
|
+// if self.collectionComponent.collectionView.contentOffset.y <= -cusH{
|
|
|
+ self.collectionComponent.collectionView.contentOffset = CGPoint(x: 0, y: -cusH)
|
|
|
+//
|
|
|
+// if scrollTop {
|
|
|
+// self.collectionComponent.collectionView.contentOffset = CGPoint(x: 0, y: -cusH)
|
|
|
+// }else {
|
|
|
+// self.collectionComponent.collectionView.contentOffset = self.collectionComponent.collectionView.contentOffset
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
func presentModalHintVC(){
|
|
@@ -349,15 +348,12 @@ extension TSPTPInputVC {
|
|
|
}
|
|
|
|
|
|
func setUpCusStackView(){
|
|
|
-
|
|
|
collectionComponent.collectionView.addSubview(cusStackView)
|
|
|
-
|
|
|
-// cusStackView.addSubviewToStack(entranceView)
|
|
|
-// entranceView.snp.makeConstraints { make in
|
|
|
-// make.height.equalTo(bannerH+bannerY)
|
|
|
-// make.width.equalTo(k_ScreenWidth)
|
|
|
-// }
|
|
|
-
|
|
|
+ cusStackView.snp.makeConstraints { make in
|
|
|
+ make.top.equalTo(-cusStackViewH)
|
|
|
+ make.leading.trailing.equalTo(0)
|
|
|
+ make.height.equalTo(cusStackViewH)
|
|
|
+ }
|
|
|
let uploadPhotoTitleView = TSTitleView.creatTitleView(title: "Upload Photo".localized, subTitle: "(Size ≤ 10MB)".localized)
|
|
|
cusStackView.addSubviewToStack(uploadPhotoTitleView)
|
|
|
uploadPhotoTitleView.snp.makeConstraints { make in
|
|
@@ -396,7 +392,6 @@ extension TSPTPInputVC {
|
|
|
make.width.equalTo(k_ScreenWidth)
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// cusStackView.addSubviewToStack(promptTextView)
|
|
|
// promptTextView.snp.makeConstraints { make in
|
|
|
// make.height.equalTo(promptTextViewH)
|
|
@@ -415,6 +410,7 @@ extension TSPTPInputVC: UITextViewDelegate{
|
|
|
// 实现 UITextViewDelegate 协议方法,控制 return 键行为
|
|
|
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
|
|
|
|
|
|
+ clearBtn.isHidden = textView.text.count <= 0
|
|
|
if text == "\n" {
|
|
|
// 当输入为换行符(即按下 return 键)时,执行相应操作
|
|
|
//sendBolck?(textView.text)
|
|
@@ -422,7 +418,6 @@ extension TSPTPInputVC: UITextViewDelegate{
|
|
|
}
|
|
|
return true
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
@@ -452,9 +447,28 @@ extension TSPTPInputVC {
|
|
|
|
|
|
|
|
|
func updateTextFiledView () {
|
|
|
-// promptTextView.snp.updateConstraints { make in
|
|
|
-// make.height.equalTo(viewModel.selectedPTPStyleModel?.style == "No Style" ? promptTextViewH : 0 )
|
|
|
-// }
|
|
|
+ if isNoneStyle {
|
|
|
+ if promptTextView.superview == nil {
|
|
|
+ cusStackView.addSubviewToStack(promptTextView)
|
|
|
+ promptTextView.snp.makeConstraints { make in
|
|
|
+ make.height.equalTo(promptTextViewH)
|
|
|
+ make.width.equalTo(k_ScreenWidth)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ cusStackView.removeViewToStack(promptTextView)
|
|
|
+ }
|
|
|
+
|
|
|
+ kDelayMainShort {
|
|
|
+ self.upDateCusStackViewH(scrollTop: false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var isNoneStyle:Bool{
|
|
|
+ if viewModel.selectedPTPStyleModel?.style == "No Style" {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return false
|
|
|
}
|
|
|
}
|
|
|
extension TSPTPInputVC {
|
|
@@ -471,15 +485,17 @@ extension TSPTPInputVC {
|
|
|
}
|
|
|
|
|
|
//判断 vip
|
|
|
- if kJudgeVip(externalBool: isVip, vc: self) { [weak self] in
|
|
|
- guard let self = self else { return }
|
|
|
- }{ return }
|
|
|
+ if kJudgeVip(externalBool: isVip, vc: self) { return }
|
|
|
|
|
|
|
|
|
guard let selectedPTPStyleModel = viewModel.selectedPTPStyleModel else { return }
|
|
|
guard let upLoadImage = viewModel.upLoadImage else { return }
|
|
|
-
|
|
|
- let gennerateVC = TSPTPGeneratorVC(prompt: viewModel.prompt,promptSort: selectedPTPStyleModel.imageText , imageUrl: "",upLoadImage: upLoadImage,style: selectedPTPStyleModel.style) { [weak self] model in
|
|
|
+ var prompt = viewModel.prompt
|
|
|
+ if isNoneStyle {
|
|
|
+ prompt = customTextView.text
|
|
|
+ }
|
|
|
+
|
|
|
+ let gennerateVC = TSPTPGeneratorVC(prompt:prompt,promptSort: selectedPTPStyleModel.imageText , imageUrl: "",upLoadImage: upLoadImage,style: selectedPTPStyleModel.style) { [weak self] model in
|
|
|
guard let self = self else { return }
|
|
|
if viewModel.saveModel(model:model) {
|
|
|
collectionComponent.clear()
|
|
@@ -499,41 +515,29 @@ extension TSPTPInputVC {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-extension TSPTPInputVC {
|
|
|
-
|
|
|
- @objc func keyboardWillShow(_ notification: Notification) {
|
|
|
|
|
|
- guard let keyboardFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect,
|
|
|
- let animationDuration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? TimeInterval else {
|
|
|
- return
|
|
|
- }
|
|
|
-// 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
|
|
|
-//// }
|
|
|
-
|
|
|
-// kDelayMainShort {
|
|
|
-// self.collectionComponent.collectionView.scrollToLastItem(animated: false)
|
|
|
-// }
|
|
|
- }
|
|
|
-
|
|
|
- @objc func keyboardWillHide(_ notification: Notification) {
|
|
|
- guard let animationDuration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? TimeInterval else {
|
|
|
- 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
|
|
|
-//// }
|
|
|
+extension TSPTPInputVC {
|
|
|
+ // MARK: - 键盘弹出时滚动到 TextView
|
|
|
+ @objc func keyboardWillShow(_ notification: Notification) {
|
|
|
+ guard let keyboardFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return }
|
|
|
+ let textView = customTextView
|
|
|
+ guard let scrollView = collectionComponent.collectionView else { return }
|
|
|
+ // 1. 计算键盘高度(减去安全区域)
|
|
|
+ let keyboardHeight = keyboardFrame.height - view.safeAreaInsets.bottom
|
|
|
+ dePrint("keyboardHeight = \(keyboardHeight )")
|
|
|
+ // 2. 直接获取 TextView 在 ScrollView 中的位置
|
|
|
+ let textViewFrame = scrollView.convert(textView.frame, from: textView.superview)
|
|
|
+ dePrint("textViewFrame = \(textViewFrame)")
|
|
|
+ // 3. 计算需要滚动的距离(TextView 底部 - (屏幕高度 - 键盘高度))
|
|
|
+ var scrollDistance = textViewFrame.maxY - (scrollView.bounds.height - keyboardHeight)
|
|
|
+ dePrint("scrollDistance = \(scrollDistance)")
|
|
|
+ // 4. 如果需要滚动,调整 contentOffset
|
|
|
+ var y = scrollDistance
|
|
|
+ scrollView.setContentOffset(CGPoint(x: 0, y: y),animated: true)
|
|
|
+ }
|
|
|
+
|
|
|
+ // MARK: - 键盘隐藏时恢复
|
|
|
+ @objc private func keyboardWillHide(_ notification: Notification) {
|
|
|
+ self.collectionComponent.collectionView.contentOffset = CGPoint(x: 0, y: -cusStackViewH)
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|