diff --git a/NadoSunbae-iOS/NadoSunbae-iOS/Global/Class/WritePost/BaseWritePostVC.swift b/NadoSunbae-iOS/NadoSunbae-iOS/Global/Class/WritePost/BaseWritePostVC.swift index 4fb29d55..542e23d3 100644 --- a/NadoSunbae-iOS/NadoSunbae-iOS/Global/Class/WritePost/BaseWritePostVC.swift +++ b/NadoSunbae-iOS/NadoSunbae-iOS/Global/Class/WritePost/BaseWritePostVC.swift @@ -12,9 +12,9 @@ import RxSwift class BaseWritePostVC: BaseVC { // MARK: Properties - private let questionSV = UIScrollView() + let questionSV = UIScrollView() private let disposeBag = DisposeBag() - private var questionTextViewLineCount: Int = 1 + var questionTextViewLineCount: Int = 1 private var majorID: Int = MajorInfo.shared.selectedMajorID ?? UserDefaults.standard.value(forKey: UserDefaults.Keys.FirstMajorID) as! Int let questionWriteNaviBar = NadoSunbaeNaviBar().then { @@ -172,6 +172,7 @@ extension BaseWritePostVC { } /// textView의 상태에 따라 스크롤뷰를 Up, Down 하는 메서드 + @objc func scollByTextViewState(textView: UITextView) { var contentOffsetY = questionSV.contentOffset.y var isLineAdded = true @@ -201,6 +202,11 @@ extension BaseWritePostVC { } questionTextViewLineCount = textView.numberOfLines() } + + /// questionWriteNaviBar의 rightActivateBtn의 활성상태를 설정하는 메서드 + func setNaviBarRightActivateState(isActivated: Bool) { + questionWriteNaviBar.rightActivateBtn.isActivated = isActivated + } } // MARK: - Keyboard diff --git a/NadoSunbae-iOS/NadoSunbae-iOS/Screen/Classroom/VC/WriteQuestionVC.swift b/NadoSunbae-iOS/NadoSunbae-iOS/Screen/Classroom/VC/WriteQuestionVC.swift index a92ad1a9..58e3af8c 100644 --- a/NadoSunbae-iOS/NadoSunbae-iOS/Screen/Classroom/VC/WriteQuestionVC.swift +++ b/NadoSunbae-iOS/NadoSunbae-iOS/Screen/Classroom/VC/WriteQuestionVC.swift @@ -33,6 +33,7 @@ class WriteQuestionVC: BaseWritePostVC { setUpAlertMsgByEditState() setHighlightViewState(textField: questionTitleTextField, highlightView: textHighlightView) setActivateBtnState(textField: questionTitleTextField, textView: questionWriteTextView) + setNaviBarRightActivateState(isActivated: false) } } @@ -47,7 +48,6 @@ extension WriteQuestionVC { questionWriteTextView.setDefaultStyle(isUsePlaceholder: false, placeholderText: "") questionTitleTextField.text = originTitle questionWriteTextView.text = originContent - questionWriteNaviBar.rightActivateBtn.isActivated = true } else { questionWriteTextView.setDefaultStyle(isUsePlaceholder: true, placeholderText: "선배에게 1:1 질문을 남겨보세요.\n선배가 답변해 줄 거에요!") } @@ -81,9 +81,11 @@ extension WriteQuestionVC { } /// dismissBtn Press - questionWriteNaviBar.dismissBtn.press { + questionWriteNaviBar.dismissBtn.press { [weak self] in + guard let self = self else { return } + guard let alert = Bundle.main.loadNibNamed(NadoAlertVC.className, owner: self, options: nil)?.first as? NadoAlertVC else { return } - alert.showNadoAlert(vc: self, message: self.dismissAlertMsg, confirmBtnTitle: "계속 작성", cancelBtnTitle: "나갈래요") + alert.showNadoAlert(vc: self, message: self.dismissAlertMsg, confirmBtnTitle: self.isEditState ? "계속 수정" : "계속 작성", cancelBtnTitle: "나갈래요") alert.cancelBtn.press { self.dismiss(animated: true, completion: nil) } diff --git a/NadoSunbae-iOS/NadoSunbae-iOS/Screen/Community/VC/CommunityWriteVC.swift b/NadoSunbae-iOS/NadoSunbae-iOS/Screen/Community/VC/CommunityWriteVC.swift index 364299f1..28a72a5a 100644 --- a/NadoSunbae-iOS/NadoSunbae-iOS/Screen/Community/VC/CommunityWriteVC.swift +++ b/NadoSunbae-iOS/NadoSunbae-iOS/Screen/Community/VC/CommunityWriteVC.swift @@ -78,6 +78,7 @@ final class CommunityWriteVC: BaseWritePostVC, View { setUpCategoryCVByEditState() setHighlightViewState(textField: questionTitleTextField, highlightView: textHighlightView) setActivateBtnState(textField: questionTitleTextField, textView: questionWriteTextView) + setNaviBarRightActivateState(isActivated: false) } func bind(reactor: CommunityWriteReactor) { @@ -93,7 +94,7 @@ extension CommunityWriteVC { contentView.addSubviews([selectMajorLabel, majorSelectTextField, majorSelectBtn, categoryLabel, categoryCV, questionDescLabel, partitionBar]) selectMajorLabel.snp.makeConstraints { - $0.top.equalTo(questionWriteNaviBar.snp.bottom).offset(24) + $0.top.equalToSuperview().offset(24) $0.leading.equalToSuperview().offset(24) } @@ -168,25 +169,30 @@ extension CommunityWriteVC { .disposed(by: disposeBag) questionWriteNaviBar.rightActivateBtn.rx.tap - .subscribe(onNext: { - self.nadoAlert?.showNadoAlert(vc: self, message: self.confirmAlertMsg, confirmBtnTitle: "네", cancelBtnTitle: "아니요") + .subscribe(onNext: { [weak self] in + guard let self = self else { return } + + guard let alert = Bundle.main.loadNibNamed(NadoAlertVC.className, owner: self, options: nil)?.first as? NadoAlertVC else { return } + alert.showNadoAlert(vc: self, message: self.confirmAlertMsg, confirmBtnTitle: "네", cancelBtnTitle: "아니요") + alert.confirmBtn.press { + if self.isEditState { + reactor.action.onNext(.tapQuestionEditBtn(postID: self.postID ?? 0, title: self.questionTitleTextField.text ?? "", content: self.questionWriteTextView.text ?? "")) + } else { + reactor.action.onNext(.tapQuestionWriteBtn(type: self.selectedCategory, majorID: self.majorID ?? MajorIDConstants.regardlessMajorID, answererID: 0, title: self.questionTitleTextField.text ?? "", content: self.questionWriteTextView.text)) + } + } }) .disposed(by: disposeBag) - nadoAlert?.confirmBtn.rx.tap.map{ - if self.isEditState { - return CommunityWriteReactor.Action.tapQuestionEditBtn(postID: self.postID ?? 0, title: self.questionTitleTextField.text ?? "", content: self.questionWriteTextView.text ?? - "") - } else { - return CommunityWriteReactor.Action.tapQuestionWriteBtn(type: self.selectedCategory, majorID: self.majorID ?? MajorIDConstants.regardlessMajorID, answererID: 0, title: self.questionTitleTextField.text ?? "", content: self.questionWriteTextView.text) - } - } - .bind(to: reactor.action) - .disposed(by: disposeBag) - questionWriteNaviBar.dismissBtn.rx.tap - .subscribe(onNext: { - self.nadoAlert?.showNadoAlert(vc: self, message: self.dismissAlertMsg, confirmBtnTitle: "계속 작성", cancelBtnTitle: "나갈래요") + .subscribe(onNext: { [weak self] in + guard let self = self else { return } + + guard let alert = Bundle.main.loadNibNamed(NadoAlertVC.className, owner: self, options: nil)?.first as? NadoAlertVC else { return } + alert.showNadoAlert(vc: self, message: self.dismissAlertMsg, confirmBtnTitle: self.isEditState ? "계속 수정" : "계속 작성", cancelBtnTitle: "나갈래요") + alert.cancelBtn.press { + self.dismiss(animated: true, completion: nil) + } }) .disposed(by: disposeBag) @@ -314,6 +320,36 @@ extension CommunityWriteVC { slideVC.selectCommunityDelegate = self self.present(slideVC, animated: true) } + + override func scollByTextViewState(textView: UITextView) { + var contentOffsetY = questionSV.contentOffset.y + var isLineAdded = true + + if questionTextViewLineCount != textView.numberOfLines() { + + if questionTextViewLineCount > textView.numberOfLines() { + isLineAdded = false + } else { + isLineAdded = true + } + + if isLineAdded && textView.numberOfLines() > 2 && questionSV.contentOffset.y < 193 { + contentOffsetY += 38 + questionSV.setContentOffset(CGPoint(x: 0, y: contentOffsetY), animated: true) + + } else if !isLineAdded && questionTextViewLineCount < 9 && questionSV.contentOffset.y > 0 { + + if contentOffsetY - 38 > 0 { + contentOffsetY -= 38 + questionSV.setContentOffset(CGPoint(x: 0, y: contentOffsetY), animated: true) + } else { + contentOffsetY = 0 + questionSV.setContentOffset(CGPoint(x: 0, y: 0), animated: true) + } + } + } + questionTextViewLineCount = textView.numberOfLines() + } } // MARK: - UICollectionViewDelegateFlowLayout @@ -355,6 +391,10 @@ extension CommunityWriteVC: UITextViewDelegate { textView.text = nil textView.textColor = .mainText } + + UIView.animate(withDuration: 0.5) { [weak self] in + self?.questionSV.contentOffset.y = 193 + } } /// textViewDidChange