Browse Source

图片上传完成一半

南鑫林 5 years ago
parent
commit
9e2d6c12c6

+ 1 - 0
RainbowPlanet/RainbowPlanet/Modules/CircleModule/Circle/ViewController/CircleViewController.swift

@@ -76,6 +76,7 @@ class CircleViewController: BaseViewController {
         plusButton.rx.tap.subscribe(onNext: {[weak self] (_) in
             let vc = CirclePublishMessageViewController()
             vc.circleId = self?.communityCircleModel?.id
+            vc.maxImageCount = 3
             self?.navigationController?.pushViewController(vc, animated: true)
         }).disposed(by: disposeBag)
         loadCircleData()

+ 14 - 0
RainbowPlanet/RainbowPlanet/Modules/CircleModule/CirclePublishMessage/View/CirclePublishMessageTitleCollectionViewCell.swift

@@ -31,6 +31,7 @@ class CirclePublishMessageTitleCollectionViewCell: UICollectionViewCell {
         super.init(frame: frame)
         setupViews()
         setupLayouts()
+        setupData()
     }
     
     required init?(coder aDecoder: NSCoder) {
@@ -51,6 +52,19 @@ class CirclePublishMessageTitleCollectionViewCell: UICollectionViewCell {
         }
     }
     
+    typealias TitleTextViewChangedClosure = (String) -> Void
+    var titleTextViewChangedClosure : TitleTextViewChangedClosure?
+    
+    func setupData() {
+        titleTextView.rx.text.orEmpty.changed.subscribe(onNext: {
+            [weak self] (text) in
+            TextLimitTool.restrictionInputTextView((self?.titleTextView)!, maxNumber: 200)
+            if let titleTextViewChangedClosure = self?.titleTextViewChangedClosure {
+                titleTextViewChangedClosure(text)
+            }
+        }).disposed(by: disposeBag)
+    }
+    
     lazy var titleTextView: IQTextView = {
         let titleTextView = IQTextView()
         titleTextView.placeholder = "请输入您的问题"

+ 22 - 12
RainbowPlanet/RainbowPlanet/Modules/CircleModule/CirclePublishMessage/ViewController/CirclePublishMessageViewController.swift

@@ -23,9 +23,8 @@ class CirclePublishMessageViewController: BaseViewController {
     var circleId : Int?
     var content : String = ""
     var imgs : String = ""
-    var maxImageCount: Int = 9
-    var images = Array<UIImage>()
-
+    var maxImageCount: Int = 3
+    var selectedAssets = Array<TLPHAsset>()
     
     override func viewDidLoad() {
         super.viewDidLoad()
@@ -92,7 +91,7 @@ class CirclePublishMessageViewController: BaseViewController {
     /// 发布
     func communityCircleMessagePostApi() {
         SwiftMoyaNetWorkServiceCommunity.shared().communityCircleMessagePostApi(circleId: circleId ?? 0, content: content ,imgs: imgs) { [weak self] _ in
-            self?.navigationController?.popToRootViewController(animated: true)
+            self?.navigationController?.popViewController(animated: true)
         }
     }
 }
@@ -107,8 +106,8 @@ extension CirclePublishMessageViewController: UICollectionViewDelegateFlowLayout
         case 0:
             return 1
         default:
-            if images.count < maxImageCount {
-                return images.count + 1
+            if selectedAssets.count < maxImageCount {
+                return selectedAssets.count + 1
             } else {
                 return maxImageCount
             }
@@ -121,9 +120,13 @@ extension CirclePublishMessageViewController: UICollectionViewDelegateFlowLayout
         switch indexPath.section {
         case 0:
             let cell = CirclePublishMessageTitleCollectionViewCell.cellWith(collectionView: collectionView, indexPath: indexPath)
+            cell.titleTextViewChangedClosure = {
+                [weak self] content in
+                self?.content = content
+            }
             return cell
         default:
-            if images.count < maxImageCount && indexPath.row == images.count {
+            if selectedAssets.count < maxImageCount && indexPath.row == selectedAssets.count {
                 // 添加图片
                 let cell = PublishEditDefaultCollectionCell.cellWith(collectionView: collectionView, indexPath: indexPath)
                 cell.noteStr = "添加图片"
@@ -132,12 +135,13 @@ extension CirclePublishMessageViewController: UICollectionViewDelegateFlowLayout
                 // 展示图片
                 let cell = PublishEditAddImgCollectionCell.cellWith(collectionView: collectionView, indexPath: indexPath)
                 cell.mediaType = .image
-                if indexPath.row < images.count {
-                    cell.showImage = images[indexPath.row]
+                if indexPath.row < selectedAssets.count {
+                    let image = selectedAssets[indexPath.row].fullResolutionImage
+                    cell.showImage = image
                 }
                 cell.delPicBlock = {
                     [weak self] (index) in
-                    self?.images.remove(at: index!)
+                    self?.selectedAssets.remove(at: index!)
                     self?.collectionView.reloadSections([1])
                 }
                 return cell
@@ -179,11 +183,17 @@ extension CirclePublishMessageViewController: UICollectionViewDelegateFlowLayout
     }
     
     func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
-        if images.count < maxImageCount && indexPath.row == images.count {
+        if selectedAssets.count < maxImageCount && indexPath.row == selectedAssets.count {
             let vc = CustomTLPhotoPickerViewController()
             vc.mediaType = .image
             vc.numberOfColumn = 4
-            vc.maxSelectedAssets = 3
+            vc.maxSelectedAssets = maxImageCount
+            vc.selectedAssets = selectedAssets
+            vc.finishClosure = {
+                [weak self] selectedAssets in
+                self?.selectedAssets = selectedAssets
+                self?.collectionView.reloadSections([1])
+            }
             self.navigationController?.pushViewController(vc, animated: true)
         }
     }

+ 1 - 1
RainbowPlanet/RainbowPlanet/Tools/TLPhotoPicker/TLPhotoPicker/Custom/CustomCell_Instagram.swift

@@ -53,7 +53,7 @@ class CustomCell_Instagram: TLPhotoCollectionViewCell {
         self.selectedBgView?.backgroundColor = UIColor.clear
         self.selectedBgView?.layer.borderColor = UIColor.clear.cgColor
         self.selectedBgView?.layer.borderWidth = 1.5
-        self.orderLabel?.addTapGesture(1, target: self, action: #selector(orderSelected))
+//        self.orderLabel?.addTapGesture(1, target: self, action: #selector(orderSelected))
     }
     
     override open func prepareForReuse() {

+ 9 - 2
RainbowPlanet/RainbowPlanet/Tools/TLPhotoPicker/TLPhotoPicker/Custom/CustomTLPhotoPickerViewController.swift

@@ -30,6 +30,9 @@ class CustomTLPhotoPickerViewController: TLPhotosPickerViewController {
     var maxSelectedAssets : Int? = nil
     var allowedVideoRecording : Bool = false
     
+    typealias FinishClosure = (_ selectedAssets:[TLPHAsset]) -> Void
+    var finishClosure : FinishClosure?
+    
     lazy var customNavigationBar = WRCustomNavigationBar.CustomNavigationBar()
     
     override func viewDidLoad() {
@@ -77,8 +80,12 @@ class CustomTLPhotoPickerViewController: TLPhotosPickerViewController {
             make.centerY.equalTo(customNavigationBar.titleLabel)
         }
         
-        nextButton.rx.tap.subscribe(onNext: { (data) in
-            
+        nextButton.rx.tap.subscribe(onNext: {
+            [weak self] (data) in
+            if let finishClosure = self?.finishClosure {
+                finishClosure(self!.selectedAssets)
+            }
+            self?.navigationController?.popViewController(animated: true)
         }).disposed(by: disposeBag)
         
         if self.navigationController != nil {