123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- //
- // PublishEditContentViewController.swift
- // RainbowPlanet
- //
- // Created by 南鑫林 on 2019/11/9.
- // Copyright © 2019 RainbowPlanet. All rights reserved.
- //
- import UIKit
- class PublishEditVideoContentViewController: BaseViewController {
- var isRenewEdit : Bool = false
- /// 合成导出路径
- var outputPath : String?
- /// 发布模型
- var publishManagerModel : PublishManagerModel?
- /// 视频路径模型
- var publishManagerVideoModel : PublishManagerVideoModel?
- /// 发布内容
- var publishManagerContentModel : PublishManagerContentModel?
- /// 话题
- var publishManagerTopicModel : PublishManagerTopicModel?
- /// 定位
- var publishManagerLocationModel : PublishManagerLocationModel?
-
- override func viewDidLoad() {
- super.viewDidLoad()
- setVideoCoverImagePath()
- setupViews()
- setupLayouts()
- setupData()
- }
-
- func setVideoCoverImagePath() {
-
-
- if publishManagerModel == nil {
- // 清除图片路径
- PathURLManager.clearPath(pathURL:
- PathURLManager.projectPicturesPath(parentURL:
- PathURLManager.projectResourcesPath(parentURL:
- PathURLManager.projectRecordssPath(parentURL:
- PathURLManager.projectDocumentPath())))!)
-
- //设置录制视频封面输出路径
- let outCoverImagePathURL =
- PathURLManager.projectPathExtensionPng(parentURL:
- PathURLManager.projectFilePath(fileName:
- PathURLManager.randomString(), parentURL:
- PathURLManager.projectDateFormatPath(dateFormat: "yyyyMM", parentURL:
- PathURLManager.projectPicturesPath(parentURL:
- PathURLManager.projectResourcesPath(parentURL:
- PathURLManager.projectRecordssPath(parentURL:
- PathURLManager.projectDocumentPath()))))))!
-
- // 视频路径
- let asset = AVURLAsset.init(url: URL(fileURLWithPath: outputPath ?? ""))
- let gen = AVAssetImageGenerator.init(asset: asset)
- gen.appliesPreferredTrackTransform = true
- let time = CMTimeMakeWithSeconds(0, preferredTimescale: Int32(1 * NSEC_PER_SEC))
- var actualTime : CMTime = CMTimeMakeWithSeconds(0, preferredTimescale: 0)
- do {
- let image = try gen.copyCGImage(at: time, actualTime: &actualTime)
- //旋转修正
- let imageNew = UIImage.rotate(aImage: UIImage(cgImage: image))
- let imgData: Data? = UIImage.pngData(imageNew)()
- do {
- try imgData?.write(to: outCoverImagePathURL)
- }
- catch {
- SwiftProgressHUD.shared().showText("封面写入失败")
- NXLLog("存入失败")
- self.navigationController?.popViewController(animated: true)
- return
- }
- } catch {
- SwiftProgressHUD.shared().showText("封面写入失败")
- NXLLog("错误")
- self.navigationController?.popViewController(animated: true)
- return
- }
- publishManagerVideoModel = PublishManagerVideoModel()
- publishManagerVideoModel?.outVideoPath = outputPath
- publishManagerVideoModel?.outVideoPathURL = URL(fileURLWithPath: outputPath ?? "")
- publishManagerVideoModel?.outCoverImagePath = outCoverImagePathURL.path
- publishManagerVideoModel?.outCoverImagePathURL = outCoverImagePathURL
- //发布内容
- publishManagerContentModel = PublishManagerContentModel()
- // 话题
- publishManagerTopicModel = PublishManagerTopicModel()
- // 定位
- publishManagerLocationModel = PublishManagerLocationModel()
- }else {
- // 视频路径
- publishManagerVideoModel = publishManagerModel?.video
- //发布内容
- publishManagerContentModel = publishManagerModel?.content
- // 话题
- publishManagerTopicModel = publishManagerModel?.topic
- // 定位
- publishManagerLocationModel = publishManagerModel?.location
- }
- }
-
- override func setupViews() {
- navigationBar.wr_setBottomLineHidden(hidden: true)
- view.addSubview(publishButton)
- view.addSubview(tableView)
-
- }
-
- override func setupLayouts() {
- publishButton.snp.makeConstraints { (make) in
- make.centerY.equalTo(navigationBar.leftButton)
- make.right.equalTo(-14)
- make.width.equalTo(64)
- make.height.equalTo(26)
- }
- tableView.snp.makeConstraints { (make) in
- make.top.equalTo(kNavBarTotalHeight)
- make.left.right.bottom.equalToSuperview()
- }
- }
-
- override func setupData() {
-
- publishButton.rx.tap.subscribe(onNext: { [weak self] (data) in
- self?.publishAction()
- }).disposed(by: disposeBag)
-
- }
-
- lazy var publishButton: UIButton = {
- let publishButton = UIButton()
- publishButton.setBackgroundImage(UIImage.imageWithColor(color: kThemeColor), for: UIControl.State.normal)
- publishButton.setBackgroundImage(UIImage.imageWithColor(color: kd8d8d8Color), for: UIControl.State.disabled)
- publishButton.setTitle("发布", for: UIControl.State.normal)
- publishButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
- publishButton.titleLabel?.font = kMediumFont13
- publishButton.cornerRadius = 13
- publishButton.masksToBounds = true
- return publishButton
- }()
-
- lazy var tableView: UITableView = {
- let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped)
- tableView.separatorStyle = .none
- tableView.backgroundColor = kffffffColor
- tableView.dataSource = self
- tableView.delegate = self
- return tableView
- }()
-
- typealias POPClosure = () -> Void
- var popClosure : POPClosure?
-
- override func didMove(toParent parent: UIViewController?) {
- if !(parent != nil) {
- if let popClosure = popClosure {
- popClosure()
- }
- }
- }
-
- func publishAction() {
- if publishManagerContentModel?.detailTitle?.count == 0 || publishManagerContentModel?.detailTitle == nil || publishManagerContentModel?.detailTitle == "" {
- SwiftProgressHUD.shared().showText("还没输入描述内容")
- return
- }
-
- if publishManagerTopicModel?.topics?.isEmpty ?? true {
- SwiftProgressHUD.shared().showText("还没选择话题哟")
- return
- }
- if publishManagerModel == nil {
- publishManagerModel = PublishManagerModel()
- }
- publishManagerModel?.publishType = .video
- publishManagerModel?.video = publishManagerVideoModel
- publishManagerModel?.content = publishManagerContentModel
- publishManagerModel?.topic = publishManagerTopicModel
- publishManagerModel?.location = publishManagerLocationModel
-
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "DismissFromPublishEditVc"), object: publishManagerModel)
- if isRenewEdit {
- self.navigationController?.popViewController(animated: true)
- }else {
- self.dismissToRootViewController(animated: false) {
- baseTabbarViewController?.selectedIndex = 0
- }
- }
- }
- }
- // MARK: - tableView dataSource && delegate
- extension PublishEditVideoContentViewController : UITableViewDelegate, UITableViewDataSource {
-
- func numberOfSections(in tableView: UITableView) -> Int {
- return 1
- }
-
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return 5
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- switch indexPath.row {
- case 0:
- let cell = PublishEditVideoCoverImageTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.publishManagerVideoModel = publishManagerVideoModel
- return cell
- case 1:
- let cell = PublishEditContentViewTitleCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.publishManagerContentModel = publishManagerContentModel
- cell.titleTextClosure = {
- [weak self] (text) in
- guard let strongSelf = self else { return }
- strongSelf.publishManagerContentModel?.title = text
- }
- return cell
- case 2:
- let cell = PublishEditContentViewDescribeCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.publishManagerContentModel = publishManagerContentModel
- cell.commentTextViewClosure = {
- [weak self] (text) in
- guard let strongSelf = self else { return }
- strongSelf.publishManagerContentModel?.detailTitle = text
- }
- return cell
- case 3:
- let cell = PublishNewEditTopicViewTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.publishManagerTopicModel = publishManagerTopicModel
- return cell
- case 4:
- let cell = PublishNewEditLocationTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.publishManagerLocationModel = publishManagerLocationModel
- return cell
- default:
- return UITableViewCell()
- }
- }
-
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- switch indexPath.row {
- case 3:
- let vc = PublishAddTopicController()
- vc.selTopicModelArr = publishManagerTopicModel?.topics ?? []
- vc.selTopicsClosure = {
- [weak self] (topicMdlArr) in
- self?.publishManagerTopicModel?.topics = topicMdlArr
- self?.tableView.reloadRows(at: [indexPath], with: UITableView.RowAnimation.none)
- }
- self.navigationController?.pushViewController(vc, animated: true)
- case 4:
- let vc = PublishAddAddressController()
- vc.selectLocationClosure = {
- [weak self] (address,latitude,longitude) in
- if address == "" && address == "" && longitude == "" {
- self?.publishManagerLocationModel?.address = nil
- self?.publishManagerLocationModel?.latitude = nil
- self?.publishManagerLocationModel?.longitude = nil
- } else {
- self?.publishManagerLocationModel?.address = address
- self?.publishManagerLocationModel?.latitude = latitude
- self?.publishManagerLocationModel?.longitude = longitude
- }
- self?.tableView.reloadRows(at: [indexPath], with: UITableView.RowAnimation.none)
- }
- self.navigationController?.pushViewController(vc, animated: true)
- default:
- break
- }
- }
-
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- switch indexPath.row {
- case 0:
- return 130
- case 1,3,4:
- return 50
- case 2:
- return 175
- default:
- return UITableView.automaticDimension
- }
- }
-
- func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
- return 0.000001
- }
-
- func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
- return nil
- }
-
- func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
- return 0.000001
- }
-
- func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
- return nil
- }
- }
|