|
@@ -7,6 +7,7 @@
|
|
|
|
|
|
//import IQKeyboardManagerSwift
|
|
|
import PhotosUI
|
|
|
+import MXParallaxHeader
|
|
|
class TSPTPInputVC: TSBaseVC {
|
|
|
|
|
|
lazy var viewModel: TSPTPInputVM = {
|
|
@@ -120,14 +121,14 @@ class TSPTPInputVC: TSBaseVC {
|
|
|
//###################################### 输入框 ######################################
|
|
|
lazy var customTextView: TSPlaceholderTextView = {
|
|
|
let customTextView = TSPlaceholderTextView(
|
|
|
- placeholder: "Please describe your photo".localized,
|
|
|
+ placeholder: "Describe how you want to transform".localized,
|
|
|
text: "",
|
|
|
font: .font(size: 14),
|
|
|
textColor: .white,
|
|
|
backgroundColor: .clear
|
|
|
)
|
|
|
customTextView.delegate = self
|
|
|
- customTextView.returnKeyType = .send
|
|
|
+ customTextView.returnKeyType = .done
|
|
|
return customTextView
|
|
|
}()
|
|
|
|
|
@@ -139,6 +140,7 @@ class TSPTPInputVC: TSBaseVC {
|
|
|
{ [weak self] in
|
|
|
guard let self = self else { return }
|
|
|
customTextView.text = ""
|
|
|
+ textViewDidChange(customTextView)
|
|
|
}
|
|
|
clearBtn.isHidden = true
|
|
|
return clearBtn
|
|
@@ -168,9 +170,9 @@ class TSPTPInputVC: TSBaseVC {
|
|
|
}
|
|
|
|
|
|
clearBtn.snp.makeConstraints { make in
|
|
|
- make.centerY.equalToSuperview()
|
|
|
make.width.height.equalTo(16.0)
|
|
|
make.trailing.equalTo(-12)
|
|
|
+ make.bottom.equalTo(-12.0)
|
|
|
}
|
|
|
|
|
|
return promptTextView
|
|
@@ -237,13 +239,11 @@ class TSPTPInputVC: TSBaseVC {
|
|
|
make.edges.equalToSuperview()
|
|
|
}
|
|
|
|
|
|
-
|
|
|
contentView.addSubview(collectionComponent.collectionView)
|
|
|
collectionComponent.collectionView.snp.makeConstraints { make in
|
|
|
make.edges.equalToSuperview()
|
|
|
}
|
|
|
|
|
|
-
|
|
|
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(clickView))
|
|
|
tapGesture.cancelsTouchesInView = false
|
|
|
view.addGestureRecognizer(tapGesture)
|
|
@@ -260,10 +260,12 @@ class TSPTPInputVC: TSBaseVC {
|
|
|
}
|
|
|
|
|
|
setUpCusStackView()
|
|
|
-
|
|
|
- upDateCusStackViewH()
|
|
|
+
|
|
|
kDelayMainShort {
|
|
|
- self.upDateCusStackViewH()
|
|
|
+ self.collectionComponent.collectionView.parallaxHeader.view = self.cusStackView
|
|
|
+ self.collectionComponent.collectionView.parallaxHeader.height = self.cusStackViewH
|
|
|
+ self.collectionComponent.collectionView.parallaxHeader.mode = .bottom
|
|
|
+ self.collectionComponent.collectionView.parallaxHeader.minimumHeight = 0
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -271,15 +273,16 @@ class TSPTPInputVC: TSBaseVC {
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(vipInfoChanged), name: .kPurchaseDidChanged, object: nil)
|
|
|
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)
|
|
|
+
|
|
|
+ // collectionViewObserverHandle()
|
|
|
}
|
|
|
|
|
|
|
|
|
// private var collectionViewObserver: CollectionViewObserver!
|
|
|
-//
|
|
|
// func collectionViewObserverHandle(){
|
|
|
// collectionViewObserver = CollectionViewObserver(collectionView: collectionComponent.collectionView)
|
|
|
//
|
|
@@ -316,27 +319,7 @@ extension TSPTPInputVC {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func upDateCusStackViewH(scrollTop:Bool = true){
|
|
|
- let cusH = cusStackViewH
|
|
|
- self.collectionComponent.collectionView.contentInset = UIEdgeInsets(top: cusH, left: 0, bottom: collectionViewBtootm, right: 0)
|
|
|
|
|
|
- cusStackView.snp.updateConstraints { make in
|
|
|
- make.top.equalTo(-cusH)
|
|
|
- make.height.equalTo(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(){
|
|
|
hintBaseVC = TSAIListHintBaseVC(config: .defaultConfig) { [weak self] image in
|
|
|
guard let self = self else { return }
|
|
@@ -348,13 +331,8 @@ extension TSPTPInputVC {
|
|
|
}
|
|
|
|
|
|
func setUpCusStackView(){
|
|
|
- collectionComponent.collectionView.addSubview(cusStackView)
|
|
|
- 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)
|
|
|
+
|
|
|
+ let uploadPhotoTitleView = TSTitleView.creatTitleView(title: "Upload Photo".localized, subTitle: "")
|
|
|
cusStackView.addSubviewToStack(uploadPhotoTitleView)
|
|
|
uploadPhotoTitleView.snp.makeConstraints { make in
|
|
|
make.height.equalTo(uploadPhotoTitleView.viewH)
|
|
@@ -391,12 +369,7 @@ extension TSPTPInputVC {
|
|
|
make.height.equalTo(selectStyleView.viewH)
|
|
|
make.width.equalTo(k_ScreenWidth)
|
|
|
}
|
|
|
-
|
|
|
-// cusStackView.addSubviewToStack(promptTextView)
|
|
|
-// promptTextView.snp.makeConstraints { make in
|
|
|
-// make.height.equalTo(promptTextViewH)
|
|
|
-// make.width.equalTo(k_ScreenWidth)
|
|
|
-// }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
override func viewDidLayoutSubviews() {
|
|
@@ -409,18 +382,23 @@ extension TSPTPInputVC {
|
|
|
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)
|
|
|
+ clickView()
|
|
|
return false
|
|
|
}
|
|
|
return true
|
|
|
}
|
|
|
+
|
|
|
+ func textViewDidChange(_ textView: UITextView){
|
|
|
+ clearBtn.isHidden = textView.text.count <= 0
|
|
|
+ viewModel.selectedPTPStyleModel.inputText = textView.text
|
|
|
+ viewModel.gennerateChange()
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
-
|
|
|
extension TSPTPInputVC {
|
|
|
|
|
|
@objc func vipInfoChanged() {
|
|
@@ -434,7 +412,7 @@ extension TSPTPInputVC {
|
|
|
|
|
|
var showVip = kPurchaseDefault.generateVipShow(type: .picToPic)
|
|
|
if showVip == false {
|
|
|
- showVip = self.viewModel.selectedPTPStyleModel?.isVip ?? false
|
|
|
+ showVip = self.viewModel.selectedPTPStyleModel.isVip
|
|
|
}
|
|
|
|
|
|
kSetBtnVipIcon(btn: self.submitBtn, show: showVip)
|
|
@@ -446,30 +424,6 @@ extension TSPTPInputVC {
|
|
|
}
|
|
|
|
|
|
|
|
|
- func updateTextFiledView () {
|
|
|
- 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 {
|
|
|
|
|
@@ -480,22 +434,13 @@ extension TSPTPInputVC {
|
|
|
func generateImage() {
|
|
|
|
|
|
var isVip = kPurchaseDefault.freeNumAvailable(type: .picToPic) == false
|
|
|
- if viewModel.selectedPTPStyleModel?.isVip == true {
|
|
|
+ if viewModel.selectedPTPStyleModel.isVip == true {
|
|
|
isVip = true
|
|
|
}
|
|
|
+ if kJudgeVip(externalBool: isVip, vc: self) { return } //判断 vip
|
|
|
|
|
|
- //判断 vip
|
|
|
- if kJudgeVip(externalBool: isVip, vc: self) { return }
|
|
|
-
|
|
|
-
|
|
|
- guard let selectedPTPStyleModel = viewModel.selectedPTPStyleModel else { return }
|
|
|
- guard let upLoadImage = viewModel.upLoadImage else { return }
|
|
|
- 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
|
|
|
+ viewModel.selectedPTPStyleModel.upLoadImage = viewModel.upLoadImage
|
|
|
+ let gennerateVC = TSPTPGeneratorVC(generateStyleModel: viewModel.selectedPTPStyleModel) { [weak self] model in
|
|
|
guard let self = self else { return }
|
|
|
if viewModel.saveModel(model:model) {
|
|
|
collectionComponent.clear()
|
|
@@ -541,3 +486,35 @@ extension TSPTPInputVC {
|
|
|
self.collectionComponent.collectionView.contentOffset = CGPoint(x: 0, y: -cusStackViewH)
|
|
|
}
|
|
|
}
|
|
|
+extension TSPTPInputVC {
|
|
|
+
|
|
|
+ func updateTextFiledView () {
|
|
|
+ if viewModel.selectedPTPStyleModel.input {
|
|
|
+ if promptTextView.superview == nil {
|
|
|
+ cusStackView.addSubviewToStack(promptTextView,length: promptTextViewH,animate: true)
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ cusStackView.removeViewToStack(promptTextView,animate: true)
|
|
|
+ }
|
|
|
+
|
|
|
+ kDelayMainShort {
|
|
|
+ self.updateViewCusStackViewH()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func updateViewCusStackViewH() {
|
|
|
+ self.collectionComponent.collectionView.parallaxHeader.height = self.cusStackViewH
|
|
|
+
|
|
|
+ let newHeight = self.cusStackViewH
|
|
|
+ let headerView = self.collectionComponent.collectionView.parallaxHeader.view!
|
|
|
+ for constraint in headerView.constraints {
|
|
|
+ if constraint.firstAttribute == .height &&
|
|
|
+ constraint.firstItem as? UIView == headerView &&
|
|
|
+ constraint.secondItem == nil {
|
|
|
+ constraint.constant = newHeight
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|