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
3079cf96
Commit
3079cf96
authored
Sep 29, 2020
by
zhangzhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改bug
parent
1daaf8c8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
143 additions
and
48 deletions
+143
-48
SHInputController.swift
ShorthandMaster/Input/Controller/SHInputController.swift
+112
-20
SHInputViewModel.swift
ShorthandMaster/Input/ViewModel/SHInputViewModel.swift
+31
-28
No files found.
ShorthandMaster/Input/Controller/SHInputController.swift
View file @
3079cf96
...
@@ -47,6 +47,10 @@ class SHInputController: SHBaseViewController
...
@@ -47,6 +47,10 @@ class SHInputController: SHBaseViewController
/// 是否是编辑
/// 是否是编辑
var
isEdited
=
false
var
isEdited
=
false
/// 是否编辑过
var
didEdited
=
false
/// 是否有音频
/// 是否有音频
var
haveAudio
=
false
var
haveAudio
=
false
...
@@ -186,6 +190,54 @@ class SHInputController: SHBaseViewController
...
@@ -186,6 +190,54 @@ class SHInputController: SHBaseViewController
self
.
shInputView
.
textView
.
attributedText
=
self
.
viewModel
.
getAttributedStringWithSHRecordModel
(
recordModel
:
self
.
dataModel
)
self
.
shInputView
.
textView
.
attributedText
=
self
.
viewModel
.
getAttributedStringWithSHRecordModel
(
recordModel
:
self
.
dataModel
)
self
.
initPlayer
()
self
.
initPlayer
()
// 修改音频时间, 保存一次
// 获取本地数据
// 笔记本列表
var
recordList
=
CRUserDefaults
.
recordList
// 当前笔记本下标
var
folderIndex
=
0
// 遍历笔记本列表找到当前笔记本下标
for
dict
in
recordList
!
{
var
folderModel
=
SHRecordFolderModel
()
folderModel
=
getDataDictWith
(
dict
:
dict
)
if
folderModel
.
id
.
isEqualTo
(
self
.
folderModel
.
id
)
{
break
}
folderIndex
+=
1
}
// 当前笔记下标
var
recordIndex
=
0
// 遍历当前笔记本的笔记列表找到当前笔记下标
for
recordModel
in
self
.
folderModel
.
dataSources
{
if
recordModel
.
pathFile
.
isEqualTo
(
self
.
dataModel
.
pathFile
)
{
break
}
recordIndex
+=
1
}
// 保存数据
self
.
folderModel
.
dataSources
[
recordIndex
]
=
self
.
dataModel
// 把添加数据后的文件夹保存到数组中
recordList
!
[
folderIndex
]
=
getDictWith
(
obj
:
self
.
folderModel
!
)
CRUserDefaults
.
recordList
=
recordList
self
.
saveSuccessCallBack
?(
self
.
folderModel
)
}
}
else
else
{
{
...
@@ -208,27 +260,47 @@ class SHInputController: SHBaseViewController
...
@@ -208,27 +260,47 @@ class SHInputController: SHBaseViewController
// MARK: 点击navigationBar左侧按钮
// MARK: 点击navigationBar左侧按钮
override
func
goback
()
override
func
goback
()
{
{
let
alert
=
UIAlertController
(
title
:
"确认退出编辑?"
,
message
:
nil
,
preferredStyle
:
.
alert
)
if
!
didEdited
{
let
leftAction
=
UIAlertAction
(
title
:
"直接退出"
,
style
:
.
destructive
)
{
(
action
)
in
self
.
navigationController
?
.
popViewController
(
animated
:
true
)
self
.
navigationController
?
.
popViewController
(
animated
:
true
)
}
}
alert
.
addAction
(
leftAction
)
else
{
let
rightAction
=
UIAlertAction
(
title
:
"保存并退出"
,
style
:
.
default
)
{
(
action
)
in
if
!
isEdited
{
self
.
didSelectedPauseAudioButton
(
sender
:
self
.
shInputView
.
bottomView
.
pauseAudioButton
)
}
self
.
didSelectedNavRightButton
()
let
alert
=
UIAlertController
(
title
:
"确认退出编辑?"
,
message
:
nil
,
preferredStyle
:
.
alert
)
let
leftAction
=
UIAlertAction
(
title
:
"直接退出"
,
style
:
.
destructive
)
{
(
action
)
in
self
.
navigationController
?
.
popViewController
(
animated
:
true
)
}
alert
.
addAction
(
leftAction
)
let
rightAction
=
UIAlertAction
(
title
:
"保存并退出"
,
style
:
.
default
)
{
(
action
)
in
self
.
didSelectedNavRightButton
()
}
alert
.
addAction
(
rightAction
)
self
.
present
(
alert
,
animated
:
true
,
completion
:
nil
)
}
}
alert
.
addAction
(
rightAction
)
self
.
present
(
alert
,
animated
:
true
,
completion
:
nil
)
}
}
// MARK: 点击navigationBar右侧按钮
// MARK: 点击navigationBar右侧按钮
@objc
func
didSelectedNavRightButton
()
@objc
func
didSelectedNavRightButton
()
{
self
.
saveData
()
self
.
navigationController
?
.
popViewController
(
animated
:
true
)
}
// MARK: 保存数据
func
saveData
()
{
{
// 获取本地数据
// 获取本地数据
// 笔记本列表
// 笔记本列表
...
@@ -349,8 +421,6 @@ class SHInputController: SHBaseViewController
...
@@ -349,8 +421,6 @@ class SHInputController: SHBaseViewController
CRUserDefaults
.
recordList
=
recordList
CRUserDefaults
.
recordList
=
recordList
self
.
saveSuccessCallBack
?(
self
.
folderModel
)
self
.
saveSuccessCallBack
?(
self
.
folderModel
)
self
.
navigationController
?
.
popViewController
(
animated
:
true
)
}
}
// MARK: 点击键盘按钮
// MARK: 点击键盘按钮
...
@@ -388,7 +458,7 @@ class SHInputController: SHBaseViewController
...
@@ -388,7 +458,7 @@ class SHInputController: SHBaseViewController
}
}
do
{
do
{
let
documentsFile
=
DocumentPath
+
self
.
viewModel
.
documentFilePath
+
"/
\(
self
.
dataModel
.
rename
)
.pdf"
let
documentsFile
=
DocumentPath
+
self
.
viewModel
.
documentFilePath
+
"/
\(
self
.
dataModel
.
rename
)
.pdf"
try
PDFGenerator
.
generate
(
self
.
shInputView
.
textView
!
,
to
:
documentsFile
)
try
PDFGenerator
.
generate
(
self
.
shInputView
.
textView
!
,
to
:
documentsFile
)
//此三方会把传入控件约束移除 需重新添加
//此三方会把传入控件约束移除 需重新添加
...
@@ -440,12 +510,19 @@ extension SHInputController: UITextViewDelegate, SHInputTextViewDelegate
...
@@ -440,12 +510,19 @@ extension SHInputController: UITextViewDelegate, SHInputTextViewDelegate
// MARK: 文字发生了变化
// MARK: 文字发生了变化
func
textViewDidChange
(
_
textView
:
UITextView
)
func
textViewDidChange
(
_
textView
:
UITextView
)
{
{
self
.
didEdited
=
true
self
.
shInputView
.
placeholder
.
isHidden
=
textView
.
text
.
length
>
0
self
.
shInputView
.
placeholder
.
isHidden
=
textView
.
text
.
length
>
0
}
}
// MARK: 文字将要变化
// MARK: 文字将要变化
func
textView
(
_
textView
:
UITextView
,
shouldChangeTextIn
range
:
NSRange
,
replacementText
text
:
String
)
->
Bool
func
textView
(
_
textView
:
UITextView
,
shouldChangeTextIn
range
:
NSRange
,
replacementText
text
:
String
)
->
Bool
{
{
if
self
.
hasEmoji
(
text
:
text
)
{
return
false
}
// 获取标题文字位置
// 获取标题文字位置
let
titleRange
=
NSRange
(
location
:
0
,
length
:
self
.
dataModel
.
rename
.
length
)
let
titleRange
=
NSRange
(
location
:
0
,
length
:
self
.
dataModel
.
rename
.
length
)
...
@@ -487,6 +564,20 @@ extension SHInputController: UITextViewDelegate, SHInputTextViewDelegate
...
@@ -487,6 +564,20 @@ extension SHInputController: UITextViewDelegate, SHInputTextViewDelegate
}
}
// MARK: 是否是emoji
func
hasEmoji
(
text
:
String
)
->
Bool
{
let
stringUtf8Length
=
text
.
lengthOfBytes
(
using
:
.
utf8
)
if
stringUtf8Length
>=
4
&&
stringUtf8Length
/
text
.
length
!=
3
{
return
true
}
else
{
return
false
}
}
// MARK: - SHInputTextView代理
// MARK: - SHInputTextView代理
// MARK: 点击删除按钮
// MARK: 点击删除按钮
func
textViewDidDelete
(
textView
:
SHInputTextView
)
func
textViewDidDelete
(
textView
:
SHInputTextView
)
...
@@ -506,7 +597,9 @@ extension SHInputController: UIImagePickerControllerDelegate, UINavigationContro
...
@@ -506,7 +597,9 @@ extension SHInputController: UIImagePickerControllerDelegate, UINavigationContro
{
{
// MARK: - 代理方法
// MARK: - 代理方法
// MARK: 选中了一张照片/拍了一张照片
// MARK: 选中了一张照片/拍了一张照片
func
imagePickerController
(
_
picker
:
UIImagePickerController
,
didFinishPickingMediaWithInfo
info
:
[
UIImagePickerController
.
InfoKey
:
Any
])
{
func
imagePickerController
(
_
picker
:
UIImagePickerController
,
didFinishPickingMediaWithInfo
info
:
[
UIImagePickerController
.
InfoKey
:
Any
])
{
self
.
didEdited
=
true
if
(
info
[
UIImagePickerController
.
InfoKey
.
originalImage
]
!=
nil
)
if
(
info
[
UIImagePickerController
.
InfoKey
.
originalImage
]
!=
nil
)
{
{
...
@@ -847,10 +940,7 @@ extension SHInputController
...
@@ -847,10 +940,7 @@ extension SHInputController
break
break
// MARK: 用户允许当前应用访问麦克风
// MARK: 用户允许当前应用访问麦克风
case
AVAuthorizationStatus
.
authorized
:
case
AVAuthorizationStatus
.
authorized
:
if
UIImagePickerController
.
isSourceTypeAvailable
(
UIImagePickerController
.
SourceType
.
camera
)
self
.
beginAddAudio
()
{
self
.
beginAddAudio
()
}
break
break
// MARK: 用户还没有做出选择
// MARK: 用户还没有做出选择
case
AVAuthorizationStatus
.
notDetermined
:
case
AVAuthorizationStatus
.
notDetermined
:
...
@@ -940,6 +1030,8 @@ extension SHInputController
...
@@ -940,6 +1030,8 @@ extension SHInputController
// MARK: 点击结束录制按钮
// MARK: 点击结束录制按钮
@objc
func
didSelectedStopAudioButton
(
sender
:
SHInputAudioButton
)
@objc
func
didSelectedStopAudioButton
(
sender
:
SHInputAudioButton
)
{
{
self
.
didEdited
=
true
recorder_mp3
.
pause
()
recorder_mp3
.
pause
()
self
.
timer
.
suspend
()
self
.
timer
.
suspend
()
...
...
ShorthandMaster/Input/ViewModel/SHInputViewModel.swift
View file @
3079cf96
...
@@ -103,36 +103,39 @@ class SHInputViewModel: NSObject {
...
@@ -103,36 +103,39 @@ class SHInputViewModel: NSObject {
// 找到图片
// 找到图片
if
imageAttachment
.
image
!=
nil
if
imageAttachment
.
image
!=
nil
{
{
// 将图片保存在本地
if
(
imageAttachment
.
image
?
.
size
.
width
)
!
>
0
&&
(
imageAttachment
.
image
?
.
size
.
height
)
!
>
0
// 把图片转成Data类型
let
imageData
:
Data
=
(
imageAttachment
.
image
?
.
jpegData
(
compressionQuality
:
1.0
))
!
// 保存的本地路径
let
imagePath
=
self
.
documentFilePath
+
"/image"
+
imagesPathArray
.
count
.
string
+
".jpeg"
let
imageUrl
:
URL
=
URL
(
fileURLWithPath
:
DocumentPath
+
imagePath
)
var
saveSucceed
:
Bool
=
Bool
(
true
)
// 将图片保存到沙盒
do
{
{
try
imageData
.
write
(
to
:
imageUrl
)
// 将图片保存在本地
}
catch
let
error
// 把图片转成Data类型
{
let
imageData
:
Data
=
(
imageAttachment
.
image
?
.
jpegData
(
compressionQuality
:
1.0
))
!
saveSucceed
=
false
print
(
error
)
// 保存的本地路径
}
let
imagePath
=
self
.
documentFilePath
+
"/image"
+
imagesPathArray
.
count
.
string
+
".jpeg"
if
saveSucceed
let
imageUrl
:
URL
=
URL
(
fileURLWithPath
:
DocumentPath
+
imagePath
)
{
// 保存成功后存储保存的路径
var
saveSucceed
:
Bool
=
Bool
(
true
)
imagesPathArray
.
append
(
imagePath
)
// 将图片保存到沙盒
do
{
try
imageData
.
write
(
to
:
imageUrl
)
}
catch
let
error
{
saveSucceed
=
false
print
(
error
)
}
// 存储图片位置
if
saveSucceed
imagesIndexArray
.
append
(
range
.
location
)
{
// 保存成功后存储保存的路径
imagesPathArray
.
append
(
imagePath
)
// 存储图片位置
imagesIndexArray
.
append
(
range
.
location
)
}
}
}
}
}
}
}
...
...
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