Commit 486b54c9 authored by zhangzhe's avatar zhangzhe

no message

parent 2bf0510d
......@@ -12,7 +12,9 @@ import Photos
class SHInputController: SHBaseViewController
{
// MARK: - property
private var viewModel : SHInputViewModel = SHInputViewModel()
// private var viewModel : SHInputViewModel = SHInputViewModel()
/// 存储数据的model
private var dataModel : SHRecordModel = SHRecordModel()
private var shInputView : SHInputView!
private let recorder_mp3: SHMp3RecordManager = SHMp3RecordManager.shared()
......@@ -63,7 +65,8 @@ class SHInputController: SHBaseViewController
let titleString = NSAttributedString(string: historyDic["title"] as! String, attributes: (SHInputViewModel.titleAttributes() as! [NSAttributedString.Key : Any]))
attributeString.append(titleString)
self.viewModel.title = titleString.string
// self.viewModel.title = titleString.string
self.dataModel.rename = titleString.string
let contentString = NSAttributedString(string: historyDic["content"] as! String, attributes: SHInputViewModel.contentAttributes() as? [NSAttributedString.Key : Any])
attributeString.append(contentString)
......@@ -131,50 +134,28 @@ class SHInputController: SHBaseViewController
// MARK: 点击navigationBar右侧按钮
@objc func didSelectedNavRightButton()
{
self.viewModel.imageArray = SHInputViewModel.getImageArrayWithTextView(textView: self.shInputView.textView)
self.viewModel.content = self.shInputView.textView.text.substring(self.viewModel.title.length, length: self.shInputView.textView.text.length - self.viewModel.title.length)!
self.dataModel.imageArray = SHInputViewModel.getImageArrayWithTextView(textView: self.shInputView.textView)
self.dataModel.txt = self.shInputView.textView.text.substring(self.dataModel.rename.length, length: self.shInputView.textView.text.length - self.dataModel.rename.length)!
// var dic : [String : Any] = Dictionary()
// dic.updateValue(self.viewModel.title, forKey: "title")
// dic.updateValue(self.viewModel.content, forKey: "content")
// dic.updateValue(self.viewModel.imageArray, forKey: "imageArray")
//
// UserDefaults.standard.setValue(dic, forKey: "InputRecord")
// UserDefaults.standard.synchronize()
var recordList = CRUserDefaults.recordList
var dic : [String : Any] = Dictionary()
dic.updateValue(self.viewModel.title, forKey: "title")
dic.updateValue(self.viewModel.content, forKey: "content")
dic.updateValue(self.viewModel.imageArray, forKey: "imageArray")
let modelDictionary = getDictWith(obj: self.dataModel)
UserDefaults.standard.setValue(dic, forKey: "InputRecord")
UserDefaults.standard.synchronize()
recordList?.append(<#T##newElement: Dictionary<String, Any>##Dictionary<String, Any>#>)
CRUserDefaults.recordList = [modelDictionary]
self.navigationController?.popViewController(animated: true)
}
// MARK: 获取textView中的图片数据, 保存成一个数组
// func getImageArrayWithTextView(textView : UITextView) -> Array<Any>
// {
// var imageArray = Array<Any>()
//
// let attributedString = textView.attributedText
//
// attributedString?.enumerateAttribute(NSAttributedString.Key.attachment, in: NSRange(location: 0, length: attributedString!.length), options: NSAttributedString.EnumerationOptions.longestEffectiveRangeNotRequired, using: { (attributes, range, stop) in
//
// var imageDictionary : Dictionary<String, Any> = Dictionary()
//
// if attributes != nil
// {
// let imageAttachment = attributes as! NSTextAttachment
//
// if imageAttachment.image != nil
// {
// imageDictionary.updateValue(UIImage.jpegData(imageAttachment.image!), forKey: "imageData")
// imageDictionary.updateValue(range.location, forKey: "imageLocation")
//
// imageArray.append(imageDictionary)
// }
// }
//
// })
//
// return imageArray
// }
// MARK: 点击键盘按钮
@objc func didSelectedKeyboardButton(sender : UIButton)
{
......@@ -203,7 +184,7 @@ extension SHInputController: UITextViewDelegate, SHInputTextViewDelegate
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool
{
// 获取标题文字位置
let titleRange = NSRange(location: 0, length: self.viewModel.title.length)
let titleRange = NSRange(location: 0, length: self.dataModel.rename.length)
// 在标题位置输入的内容为标题
if range.location <= titleRange.location + titleRange.length
......@@ -224,7 +205,7 @@ extension SHInputController: UITextViewDelegate, SHInputTextViewDelegate
textViewString.insert(text, at: range.location)
// 保存标题文字
self.viewModel.title = textViewString.substring(with: NSRange(location: 0, length: range.location + text.length))
self.dataModel.rename = textViewString.substring(with: NSRange(location: 0, length: range.location + text.length))
}
}
else
......@@ -317,17 +298,20 @@ extension SHInputController: UIImagePickerControllerDelegate, UINavigationContro
let newSize = CGSize(width: newWidth, height: newHeight)
// 如果没有标题添加"未命名"作为标题
if self.viewModel.title.length == 0
{
// 标题
let titleString = NSMutableAttributedString(string: "未命名", attributes: (SHInputViewModel.titleAttributes() as! [NSAttributedString.Key : Any]))
self.shInputView.textView.attributedText = titleString
self.shInputView.placeholder.isHidden = true
self.viewModel.title = titleString.string
}
// // 如果没有标题添加"未命名"作为标题
// if self.viewModel.title.length == 0
// {
// // 标题
// let titleString = NSMutableAttributedString(string: "未命名", attributes: (SHInputViewModel.titleAttributes() as! [NSAttributedString.Key : Any]))
// self.shInputView.textView.attributedText = titleString
//
// self.shInputView.placeholder.isHidden = true
//
// self.viewModel.title = titleString.string
// }
// 如果占位文字未隐藏, 隐藏占位文字
self.shInputView.placeholder.isHidden = true
// 前文
let textString = NSMutableAttributedString(attributedString: self.shInputView.textView.attributedText)
......
......@@ -18,6 +18,9 @@ class SHInputViewModel: NSObject {
/// 图片数组
var imageArray : Array = Array<Any>()
var recordModel : SHRecordModel = SHRecordModel()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment