Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
S
ShorthandMaster
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lmj
ShorthandMaster
Commits
486b54c9
Commit
486b54c9
authored
Sep 27, 2020
by
zhangzhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
2bf0510d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
53 deletions
+40
-53
SHInputController.swift
ShorthandMaster/Input/Controller/SHInputController.swift
+37
-53
SHInputViewModel.swift
ShorthandMaster/Input/ViewModel/SHInputViewModel.swift
+3
-0
No files found.
ShorthandMaster/Input/Controller/SHInputController.swift
View file @
486b54c9
...
...
@@ -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
.
titl
e
.
length
)
let
titleRange
=
NSRange
(
location
:
0
,
length
:
self
.
dataModel
.
renam
e
.
length
)
// 在标题位置输入的内容为标题
if
range
.
location
<=
titleRange
.
location
+
titleRange
.
length
...
...
@@ -224,7 +205,7 @@ extension SHInputController: UITextViewDelegate, SHInputTextViewDelegate
textViewString
.
insert
(
text
,
at
:
range
.
location
)
// 保存标题文字
self
.
viewModel
.
titl
e
=
textViewString
.
substring
(
with
:
NSRange
(
location
:
0
,
length
:
range
.
location
+
text
.
length
))
self
.
dataModel
.
renam
e
=
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
)
...
...
ShorthandMaster/Input/ViewModel/SHInputViewModel.swift
View file @
486b54c9
...
...
@@ -18,6 +18,9 @@ class SHInputViewModel: NSObject {
/// 图片数组
var
imageArray
:
Array
=
Array
<
Any
>
()
var
recordModel
:
SHRecordModel
=
SHRecordModel
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment