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
92f0fb20
Commit
92f0fb20
authored
Sep 29, 2020
by
zhangzhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新建笔记页
parent
483eb3fe
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
336 additions
and
65 deletions
+336
-65
SHInputController.swift
ShorthandMaster/Input/Controller/SHInputController.swift
+262
-61
SHInputBottomView.swift
ShorthandMaster/Input/View/SHInputBottomView.swift
+72
-3
SHInputView.swift
ShorthandMaster/Input/View/SHInputView.swift
+2
-1
No files found.
ShorthandMaster/Input/Controller/SHInputController.swift
View file @
92f0fb20
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
import
UIKit
import
UIKit
import
Photos
import
Photos
import
PDFGenerator
class
SHInputController
:
SHBaseViewController
class
SHInputController
:
SHBaseViewController
{
{
...
@@ -31,11 +32,15 @@ class SHInputController: SHBaseViewController
...
@@ -31,11 +32,15 @@ class SHInputController: SHBaseViewController
let
timer
=
DispatchSource
.
makeTimerSource
(
flags
:
[],
queue
:
DispatchQueue
.
global
())
let
timer
=
DispatchSource
.
makeTimerSource
(
flags
:
[],
queue
:
DispatchQueue
.
global
())
/// 音频播放器
/// 音频播放器
var
audioPlayer
:
AVAudioPlayer
=
AVAudioPlayer
()
var
audioPlayer
:
AVAudioPlayer
?
/// 播放计时器
/// 播放计时器
let
playTimer
=
DispatchSource
.
makeTimerSource
(
flags
:
[],
queue
:
DispatchQueue
.
global
())
let
playTimer
=
DispatchSource
.
makeTimerSource
(
flags
:
[],
queue
:
DispatchQueue
.
global
())
/// 是否是编辑
var
isEdited
=
false
private
var
shInputView
:
SHInputView
!
private
var
shInputView
:
SHInputView
!
...
@@ -55,9 +60,13 @@ class SHInputController: SHBaseViewController
...
@@ -55,9 +60,13 @@ class SHInputController: SHBaseViewController
self
.
navigationItem
.
rightBarButtonItem
=
UIBarButtonItem
.
init
(
image
:
UIImage
(
named
:
"record_nav_confirm"
)?
.
withRenderingMode
(
.
alwaysOriginal
),
style
:
.
plain
,
target
:
self
,
action
:
#selector(
didSelectedNavRightButton
)
)
self
.
navigationItem
.
rightBarButtonItem
=
UIBarButtonItem
.
init
(
image
:
UIImage
(
named
:
"record_nav_confirm"
)?
.
withRenderingMode
(
.
alwaysOriginal
),
style
:
.
plain
,
target
:
self
,
action
:
#selector(
didSelectedNavRightButton
)
)
self
.
addSubviews
()
self
.
isEdited
=
self
.
dataModel
.
rename
.
length
>
0
self
.
setUpSubviewsLocation
()
// 初始化播放器
if
self
.
isEdited
{
self
.
initPlayer
()
}
// 初始化录音计时器
// 初始化录音计时器
timer
.
schedule
(
deadline
:
.
now
(),
repeating
:
1
)
timer
.
schedule
(
deadline
:
.
now
(),
repeating
:
1
)
...
@@ -75,36 +84,66 @@ class SHInputController: SHBaseViewController
...
@@ -75,36 +84,66 @@ class SHInputController: SHBaseViewController
self
.
playTimer
.
setEventHandler
{
self
.
playTimer
.
setEventHandler
{
DispatchQueue
.
main
.
sync
{
DispatchQueue
.
main
.
sync
{
self
.
shInputView
.
bottomView
.
progressView
.
slider
.
value
=
Float
(
self
.
audioPlayer
.
currentTime
)
/
Float
(
self
.
dataModel
.
during
)
self
.
shInputView
.
bottomView
.
progressView
.
slider
.
value
=
Float
(
self
.
audioPlayer
?
.
currentTime
??
0
)
/
Float
(
self
.
audioPlayer
?
.
duration
??
0
)
self
.
shInputView
.
bottomView
.
progressView
.
timeLabel
.
text
=
self
.
viewModel
.
getTimeStringWithSeconds
(
seconds
:
NSInteger
(
self
.
audioPlayer
.
currentTime
))
self
.
shInputView
.
bottomView
.
progressView
.
timeLabel
.
text
=
self
.
viewModel
.
getTimeStringWithSeconds
(
seconds
:
NSInteger
(
self
.
audioPlayer
?
.
currentTime
??
0
))
}
}
}
}
self
.
addSubviews
()
self
.
setUpSubviewsLocation
()
}
}
override
func
viewDidDisappear
(
_
animated
:
Bool
)
{
override
func
viewDidDisappear
(
_
animated
:
Bool
)
{
super
.
viewDidDisappear
(
animated
)
super
.
viewDidDisappear
(
animated
)
var
isPush
=
false
if
let
viewControllers
=
self
.
navigationController
?
.
viewControllers
{
for
controller
in
viewControllers
{
if
controller
.
isKind
(
of
:
SHInputController
.
self
)
{
isPush
=
true
}
}
}
else
{
}
if
!
isPush
{
self
.
timer
.
suspend
()
self
.
timer
.
suspend
()
self
.
timer
.
cancel
()
self
.
timer
.
cancel
()
recorder_mp3
.
stop
()
self
.
shInputView
.
bottomView
.
timer
.
suspend
()
self
.
shInputView
.
bottomView
.
timer
.
suspend
()
self
.
shInputView
.
bottomView
.
timer
.
cancel
()
self
.
shInputView
.
bottomView
.
timer
.
cancel
()
self
.
playTimer
.
suspend
()
self
.
playTimer
.
suspend
()
self
.
playTimer
.
cancel
()
self
.
playTimer
.
cancel
()
if
self
.
audioPlayer
.
isPlaying
if
((
self
.
audioPlayer
?
.
isPlaying
)
!=
nil
)
{
{
self
.
audioPlayer
.
stop
()
self
.
audioPlayer
!.
stop
()
}
}
}
}
}
// MARK: - UI
// MARK: - UI
func
addSubviews
()
func
addSubviews
()
{
{
self
.
shInputView
=
SHInputView
.
init
(
frame
:
.
zero
,
isEdited
:
self
.
dataModel
.
rename
.
length
>
0
)
self
.
shInputView
=
SHInputView
.
init
(
frame
:
.
zero
,
isEdited
:
self
.
isEdited
)
self
.
shInputView
.
textView
.
delegate
=
self
;
self
.
shInputView
.
textView
.
delegate
=
self
;
self
.
shInputView
.
textView
.
shDelegate
=
self
;
self
.
shInputView
.
textView
.
shDelegate
=
self
;
self
.
view
.
addSubview
(
self
.
shInputView
!
)
self
.
view
.
addSubview
(
self
.
shInputView
!
)
if
self
.
isEdited
{
self
.
shInputView
.
bottomView
.
playView
.
timeLabel
.
text
=
self
.
viewModel
.
getTimeStringWithSeconds
(
seconds
:
NSInteger
(
self
.
audioPlayer
?
.
duration
??
0
))
}
// 添加点击事件
// 添加点击事件
self
.
shInputView
.
bottomView
.
imageButton
.
addTarget
(
self
,
action
:
#selector(
didSelectedImageButton(sender:)
)
,
for
:
UIControl
.
Event
.
touchUpInside
)
self
.
shInputView
.
bottomView
.
imageButton
.
addTarget
(
self
,
action
:
#selector(
didSelectedImageButton(sender:)
)
,
for
:
UIControl
.
Event
.
touchUpInside
)
self
.
shInputView
.
bottomView
.
addAudioButton
.
addTarget
(
self
,
action
:
#selector(
didSelectedAddAudioButton(sender:)
)
,
for
:
UIControl
.
Event
.
touchUpInside
)
self
.
shInputView
.
bottomView
.
addAudioButton
.
addTarget
(
self
,
action
:
#selector(
didSelectedAddAudioButton(sender:)
)
,
for
:
UIControl
.
Event
.
touchUpInside
)
...
@@ -115,18 +154,24 @@ class SHInputController: SHBaseViewController
...
@@ -115,18 +154,24 @@ class SHInputController: SHBaseViewController
self
.
shInputView
.
bottomView
.
progressView
.
beforeButton
.
addTarget
(
self
,
action
:
#selector(
didSelectedBeforeButton(sender:)
)
,
for
:
.
touchUpInside
)
self
.
shInputView
.
bottomView
.
progressView
.
beforeButton
.
addTarget
(
self
,
action
:
#selector(
didSelectedBeforeButton(sender:)
)
,
for
:
.
touchUpInside
)
self
.
shInputView
.
bottomView
.
progressView
.
laterButton
.
addTarget
(
self
,
action
:
#selector(
didSelectedLaterButton(sender:)
)
,
for
:
.
touchUpInside
)
self
.
shInputView
.
bottomView
.
progressView
.
laterButton
.
addTarget
(
self
,
action
:
#selector(
didSelectedLaterButton(sender:)
)
,
for
:
.
touchUpInside
)
self
.
shInputView
.
bottomView
.
progressView
.
slider
.
addTarget
(
self
,
action
:
#selector(
sliderTouchBegin(sender:)
)
,
for
:
.
touchDown
)
self
.
shInputView
.
bottomView
.
progressView
.
slider
.
addTarget
(
self
,
action
:
#selector(
sliderTouchBegin(sender:)
)
,
for
:
.
touchDown
)
self
.
shInputView
.
bottomView
.
progressView
.
slider
.
addTarget
(
self
,
action
:
#selector(
sliderMoving(sender:)
)
,
for
:
.
valueChanged
)
self
.
shInputView
.
bottomView
.
progressView
.
slider
.
addTarget
(
self
,
action
:
#selector(
sliderTouchEnd(sender:)
)
,
for
:
.
touchUpInside
)
self
.
shInputView
.
bottomView
.
progressView
.
slider
.
addTarget
(
self
,
action
:
#selector(
sliderTouchEnd(sender:)
)
,
for
:
.
touchUpInside
)
self
.
shInputView
.
bottomView
.
progressView
.
slider
.
addTarget
(
self
,
action
:
#selector(
sliderTouchEnd(sender:)
)
,
for
:
.
touchUpOutside
)
self
.
shInputView
.
bottomView
.
playView
.
playButton
.
addTarget
(
self
,
action
:
#selector(
didSelectedPlayButton(sender:)
)
,
for
:
.
touchUpInside
)
self
.
shInputView
.
bottomView
.
playView
.
playButton
.
addTarget
(
self
,
action
:
#selector(
didSelectedPlayButton(sender:)
)
,
for
:
.
touchUpInside
)
self
.
shInputView
.
bottomView
.
playView
.
speedButton
.
addTarget
(
self
,
action
:
#selector(
didSelectedSpeedButton(sender:)
)
,
for
:
.
touchUpInside
)
self
.
shInputView
.
bottomView
.
playView
.
speedButton
.
addTarget
(
self
,
action
:
#selector(
didSelectedSpeedButton(sender:)
)
,
for
:
.
touchUpInside
)
self
.
shInputView
.
bottomView
.
copyButton
.
addTarget
(
self
,
action
:
#selector(
didSelectedCopyButton(sender:)
)
,
for
:
.
touchUpInside
)
self
.
shInputView
.
bottomView
.
shareButton
.
addTarget
(
self
,
action
:
#selector(
didSelectedShareButton(sender:)
)
,
for
:
.
touchUpInside
)
// 有记录显示记录
// 有记录显示记录
if
self
.
dataModel
.
rename
.
length
>
0
if
self
.
isEdited
{
{
// 隐藏占位文字
// 隐藏占位文字
self
.
shInputView
.
placeholder
.
isHidden
=
true
self
.
shInputView
.
placeholder
.
isHidden
=
true
// 显示记录
// 显示记录
self
.
shInputView
.
textView
.
attributedText
=
self
.
viewModel
.
getAttributedStringWithSHRecordModel
(
recordModel
:
self
.
dataModel
)
self
.
shInputView
.
textView
.
attributedText
=
self
.
viewModel
.
getAttributedStringWithSHRecordModel
(
recordModel
:
self
.
dataModel
)
self
.
initPlayer
()
}
}
else
else
{
{
...
@@ -157,11 +202,60 @@ class SHInputController: SHBaseViewController
...
@@ -157,11 +202,60 @@ class SHInputController: SHBaseViewController
// MARK: 点击navigationBar右侧按钮
// MARK: 点击navigationBar右侧按钮
@objc
func
didSelectedNavRightButton
()
@objc
func
didSelectedNavRightButton
()
{
{
// 获取本地数据
// 笔记本列表
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
// 以前笔记上层文件夹
var
oldDocumentFilePath
=
""
// 以前笔记音频数据
var
oldPathFile
=
""
var
oldPcmPathFile
=
""
if
self
.
isEdited
{
// 遍历当前笔记本的笔记列表找到当前笔记下标
for
recordModel
in
self
.
folderModel
.
dataSources
{
if
recordModel
.
pathFile
.
isEqualTo
(
self
.
dataModel
.
pathFile
)
{
oldDocumentFilePath
=
recordModel
.
pathFile
.
substring
(
0
,
length
:
19
)
!
oldPathFile
=
recordModel
.
pathFile
oldPcmPathFile
=
recordModel
.
pcmPathFile
break
}
recordIndex
+=
1
}
}
self
.
dataModel
.
recordingType
=
1
self
.
dataModel
.
recordingType
=
1
self
.
dataModel
.
createDate
=
Date
()
self
.
dataModel
.
createDate
=
Date
()
self
.
dataModel
.
modifyDate
=
Date
()
self
.
dataModel
.
modifyDate
=
Date
()
// 重新遍历图片, 保存到新的位置
let
imageArray
=
self
.
viewModel
.
setUpImageArrayWithTextView
(
textView
:
self
.
shInputView
.
textView
)
let
imageArray
=
self
.
viewModel
.
setUpImageArrayWithTextView
(
textView
:
self
.
shInputView
.
textView
)
self
.
dataModel
.
imagesPath
=
imageArray
.
imagesPathArray
self
.
dataModel
.
imagesPath
=
imageArray
.
imagesPathArray
...
@@ -181,30 +275,48 @@ class SHInputController: SHBaseViewController
...
@@ -181,30 +275,48 @@ class SHInputController: SHBaseViewController
self
.
dataModel
.
pcmPathFile
=
self
.
viewModel
.
documentFilePath
+
"/xbMixData.caf"
self
.
dataModel
.
pcmPathFile
=
self
.
viewModel
.
documentFilePath
+
"/xbMixData.caf"
// 保存到沙盒
// 保存数据
var
recordList
=
CRUserDefaults
.
recordList
if
isEdited
{
var
i
=
0
;
// 将音频文件保存到新的位置
// var folderModel = SHRecordFolderModel()
do
{
for
dict
in
recordList
!
try
FileManager
.
default
.
moveItem
(
atPath
:
DocumentPath
+
oldPathFile
,
toPath
:
DocumentPath
+
self
.
dataModel
.
pathFile
)
}
catch
let
error
{
{
var
model
=
SHRecordFolderModel
(
)
print
(
error
)
model
=
getDataDictWith
(
dict
:
dict
)
}
if
model
.
id
==
self
.
folderModel
.
id
do
{
try
FileManager
.
default
.
moveItem
(
atPath
:
DocumentPath
+
oldPcmPathFile
,
toPath
:
DocumentPath
+
self
.
dataModel
.
pcmPathFile
)
}
catch
let
error
{
{
model
.
dataSources
.
append
(
self
.
dataModel
)
print
(
error
)
}
self
.
folderModel
=
model
break
// 删除沙盒中之前的笔记的图片和音频资源
do
{
try
FileManager
.
default
.
removeItem
(
atPath
:
DocumentPath
+
oldDocumentFilePath
)
}
catch
let
error
{
print
(
error
)
}
}
i
+=
1
self
.
folderModel
.
dataSources
[
recordIndex
]
=
self
.
dataModel
}
else
{
self
.
folderModel
.
dataSources
.
append
(
self
.
dataModel
)
}
}
recordList
!
[
i
]
=
getDictWith
(
obj
:
self
.
folderModel
!
)
// 把添加数据后的文件夹保存到数组中
recordList
!
[
folderIndex
]
=
getDictWith
(
obj
:
self
.
folderModel
!
)
CRUserDefaults
.
recordList
=
recordList
CRUserDefaults
.
recordList
=
recordList
...
@@ -225,6 +337,58 @@ class SHInputController: SHBaseViewController
...
@@ -225,6 +337,58 @@ class SHInputController: SHBaseViewController
self
.
shInputView
.
textView
.
becomeFirstResponder
()
self
.
shInputView
.
textView
.
becomeFirstResponder
()
}
}
}
}
// MARK: 点击复制按钮
@objc
func
didSelectedCopyButton
(
sender
:
UIButton
)
{
if
self
.
shInputView
.
textView
?
.
text
.
length
==
0
{
return
}
MBProgressHUD
.
showMessage
(
"文本已复制到剪切板"
,
to
:
self
.
view
)
let
board
=
UIPasteboard
.
general
board
.
string
=
self
.
shInputView
.
textView
?
.
text
}
// MARK: 点击分享按钮
@objc
func
didSelectedShareButton
(
sender
:
UIButton
)
{
if
SHUserAccountManager
.
shared
.
isMember
==
false
{
self
.
goGoods
(
"dialog_record_success_trans_pdf"
)
return
}
do
{
let
documentsFile
=
DocumentPath
+
self
.
viewModel
.
documentFilePath
+
"/
\(
self
.
dataModel
.
rename
)
.pdf"
try
PDFGenerator
.
generate
(
self
.
shInputView
.
textView
!
,
to
:
documentsFile
)
//此三方会把传入控件约束移除 需重新添加
self
.
shInputView
.
textView
.
mas_makeConstraints
({
(
make
)
in
make
?
.
left
.
mas_equalTo
()(
20
-
5
)
make
?
.
right
.
mas_equalTo
()(
0
)
make
?
.
top
.
mas_equalTo
()(
0
)
make
?
.
bottom
.
equalTo
()(
self
.
shInputView
.
bottomView
.
mas_top
)
})
// let webvc = SHWebViewController.init()
// webvc.url = documentsFile
// self.navigationController?.pushViewController(webvc, animated: true)
let
fileURL
=
URL
.
init
(
fileURLWithPath
:
documentsFile
)
let
data
=
try
Data
.
init
(
contentsOf
:
fileURL
)
let
activityVC
=
UIActivityViewController
(
activityItems
:
[
data
,
fileURL
],
applicationActivities
:
nil
)
activityVC
.
completionWithItemsHandler
=
{
activity
,
success
,
items
,
errot
in
// result
}
present
(
activityVC
,
animated
:
true
,
completion
:
nil
)
}
catch
let
error
{
print
(
error
)
}
}
}
}
// MARK: - 输入框
// MARK: - 输入框
...
@@ -375,7 +539,7 @@ extension SHInputController: UIImagePickerControllerDelegate, UINavigationContro
...
@@ -375,7 +539,7 @@ extension SHInputController: UIImagePickerControllerDelegate, UINavigationContro
// 图片
// 图片
let
attachment
=
NSTextAttachment
.
init
()
let
attachment
=
NSTextAttachment
.
init
()
attachment
.
image
=
image
attachment
.
image
=
image
.
scaled
(
to
:
newSize
)
attachment
.
bounds
=
CGRect
(
origin
:
CGPoint
.
zero
,
size
:
newSize
)
attachment
.
bounds
=
CGRect
(
origin
:
CGPoint
.
zero
,
size
:
newSize
)
let
imageString
=
NSMutableAttributedString
(
attachment
:
attachment
)
let
imageString
=
NSMutableAttributedString
(
attachment
:
attachment
)
...
@@ -686,10 +850,10 @@ extension SHInputController
...
@@ -686,10 +850,10 @@ extension SHInputController
self
.
timer
.
cancel
()
self
.
timer
.
cancel
()
self
.
shInputView
.
bottomView
.
timer
.
cancel
()
self
.
shInputView
.
bottomView
.
timer
.
cancel
()
self
.
shInputView
.
bottomView
.
playView
.
timeLabel
.
text
=
self
.
viewModel
.
getTimeStringWithSeconds
(
seconds
:
self
.
dataModel
.
during
)
self
.
initPlayer
()
self
.
initPlayer
()
self
.
shInputView
.
bottomView
.
playView
.
timeLabel
.
text
=
self
.
viewModel
.
getTimeStringWithSeconds
(
seconds
:
NSInteger
(
self
.
audioPlayer
?
.
duration
??
0
))
self
.
shInputView
.
setNeedsUpdateConstraints
()
self
.
shInputView
.
setNeedsUpdateConstraints
()
UIView
.
animate
(
withDuration
:
0.3
)
{
UIView
.
animate
(
withDuration
:
0.3
)
{
...
@@ -714,12 +878,21 @@ extension SHInputController: AVAudioPlayerDelegate {
...
@@ -714,12 +878,21 @@ extension SHInputController: AVAudioPlayerDelegate {
// MARK: 初始化播放器
// MARK: 初始化播放器
func
initPlayer
()
func
initPlayer
()
{
{
try
?
self
.
audioPlayer
=
AVAudioPlayer
(
contentsOf
:
URL
(
fileURLWithPath
:
DocumentPath
+
self
.
dataModel
.
pathFile
),
fileTypeHint
:
AVFileType
.
mp3
.
rawValue
)
do
{
try
self
.
audioPlayer
=
AVAudioPlayer
(
contentsOf
:
URL
(
fileURLWithPath
:
DocumentPath
+
self
.
dataModel
.
pathFile
),
fileTypeHint
:
AVFileType
.
mp3
.
rawValue
)
}
catch
let
error
{
print
(
error
)
return
}
// try self.audioPlayer = AVAudioPlayer(contentsOf: URL(fileURLWithPath: DocumentPath + self.dataModel.pathFile), fileTypeHint: AVFileType.mp3.rawValue)
self
.
audioPlayer
.
prepareToPlay
()
self
.
audioPlayer
?
.
prepareToPlay
()
self
.
audioPlayer
.
numberOfLoops
=
0
// 循环播放次数
self
.
audioPlayer
?
.
numberOfLoops
=
0
// 循环播放次数
self
.
audioPlayer
.
enableRate
=
true
// 允许变速播放
self
.
audioPlayer
?
.
enableRate
=
true
// 允许变速播放
self
.
audioPlayer
.
delegate
=
self
self
.
audioPlayer
?
.
delegate
=
self
// 后台播放
// 后台播放
let
session
=
AVAudioSession
.
sharedInstance
()
let
session
=
AVAudioSession
.
sharedInstance
()
...
@@ -729,9 +902,10 @@ extension SHInputController: AVAudioPlayerDelegate {
...
@@ -729,9 +902,10 @@ extension SHInputController: AVAudioPlayerDelegate {
// MARK: 点击播放/暂停按钮
// MARK: 点击播放/暂停按钮
@objc
func
didSelectedPlayButton
(
sender
:
UIButton
)
@objc
func
didSelectedPlayButton
(
sender
:
UIButton
)
{
{
if
self
.
audioPlayer
.
isPlaying
if
((
self
.
audioPlayer
?
.
isPlaying
)
!=
nil
)
{
{
self
.
audioPlayer
.
pause
()
// 暂停
self
.
audioPlayer
?
.
pause
()
self
.
playTimer
.
suspend
()
self
.
playTimer
.
suspend
()
...
@@ -739,9 +913,10 @@ extension SHInputController: AVAudioPlayerDelegate {
...
@@ -739,9 +913,10 @@ extension SHInputController: AVAudioPlayerDelegate {
}
}
else
else
{
{
// 播放
self
.
playTimer
.
resume
()
self
.
playTimer
.
resume
()
self
.
audioPlayer
.
play
()
self
.
audioPlayer
?
.
play
()
sender
.
setImage
(
UIImage
(
named
:
"input_audio_pause"
),
for
:
.
normal
)
sender
.
setImage
(
UIImage
(
named
:
"input_audio_pause"
),
for
:
.
normal
)
}
}
...
@@ -750,39 +925,65 @@ extension SHInputController: AVAudioPlayerDelegate {
...
@@ -750,39 +925,65 @@ extension SHInputController: AVAudioPlayerDelegate {
// MARK: 后退10s
// MARK: 后退10s
@objc
func
didSelectedBeforeButton
(
sender
:
UIButton
)
@objc
func
didSelectedBeforeButton
(
sender
:
UIButton
)
{
{
self
.
audioPlayer
.
currentTime
=
max
(
self
.
audioPlayer
.
currentTime
-
2
,
0
)
// self.playTimer.suspend(
)
//
self
.
audioPlayer
.
pause
()
//
self.audioPlayer.pause()
//
self
.
playTimer
.
suspend
(
)
self
.
audioPlayer
?
.
currentTime
=
max
(
self
.
audioPlayer
?
.
currentTime
??
0
-
10
,
0
)
sender
.
setImage
(
UIImage
(
named
:
"input_audio_play"
),
for
:
.
normal
)
// self.playTimer.resume()
//
// self.audioPlayer.play()
//
// self.shInputView.bottomView.playView.playButton.setImage(UIImage(named: "input_audio_play"), for: .normal)
}
}
// MARK: 前进10s
// MARK: 前进10s
@objc
func
didSelectedLaterButton
(
sender
:
UIButton
)
@objc
func
didSelectedLaterButton
(
sender
:
UIButton
)
{
{
self
.
audioPlayer
.
currentTime
=
min
(
self
.
audioPlayer
.
currentTime
+
2
,
TimeInterval
(
self
.
dataModel
.
during
))
// self.playTimer.suspend()
//
// self.audioPlayer.pause()
//
self
.
audioPlayer
?
.
currentTime
=
min
(
self
.
audioPlayer
?
.
currentTime
??
0
+
2
,
TimeInterval
(
self
.
audioPlayer
?
.
duration
??
0
))
self
.
audioPlayer
.
pause
()
// self.playTimer.resume()
//
// self.audioPlayer.play()
//
// self.shInputView.bottomView.playView.playButton.setImage(UIImage(named: "input_audio_play"), for: .normal)
}
// MARK: 开始拖动进度条
@objc
func
sliderTouchBegin
(
sender
:
UISlider
)
{
// 暂停
self
.
audioPlayer
?
.
pause
()
self
.
playTimer
.
suspend
()
self
.
playTimer
.
suspend
()
se
nder
.
setImage
(
UIImage
(
named
:
"input_audio_play"
),
for
:
.
normal
)
se
lf
.
shInputView
.
bottomView
.
playView
.
playButton
.
setImage
(
UIImage
(
named
:
"input_audio_play"
),
for
:
.
normal
)
}
}
// MARK:
开始
拖动进度条
// MARK: 拖动进度条
@objc
func
slider
TouchBegin
(
sender
:
UISlider
)
@objc
func
slider
Moving
(
sender
:
UISlider
)
{
{
self
.
didSelectedPlayButton
(
sender
:
self
.
shInputView
.
bottomView
.
playView
.
playButton
)
let
duration
:
Double
=
Double
(
self
.
audioPlayer
?
.
duration
??
0
)
self
.
shInputView
.
bottomView
.
progressView
.
timeLabel
.
text
=
self
.
viewModel
.
getTimeStringWithSeconds
(
seconds
:
NSInteger
(
Double
(
sender
.
value
)
*
duration
))
}
}
// MARK: 结束拖动进度条
// MARK: 结束拖动进度条
@objc
func
sliderTouchEnd
(
sender
:
UISlider
)
@objc
func
sliderTouchEnd
(
sender
:
UISlider
)
{
{
self
.
didSelectedPlayButton
(
sender
:
self
.
shInputView
.
bottomView
.
playView
.
playButton
)
// 播放
self
.
audioPlayer
?
.
currentTime
=
min
(
TimeInterval
(
Double
(
sender
.
value
)
*
Double
(
self
.
audioPlayer
?
.
duration
??
0
)),
Double
(
self
.
audioPlayer
?
.
duration
??
0
))
self
.
playTimer
.
resume
()
self
.
audioPlayer
?
.
play
()
self
.
audioPlayer
.
currentTime
=
TimeInterval
(
Double
(
sender
.
value
)
*
self
.
audioPlayer
.
duration
)
self
.
shInputView
.
bottomView
.
playView
.
playButton
.
setImage
(
UIImage
(
named
:
"input_audio_pause"
),
for
:
.
normal
)
}
}
// MARK: 切换倍速
// MARK: 切换倍速
...
@@ -790,17 +991,17 @@ extension SHInputController: AVAudioPlayerDelegate {
...
@@ -790,17 +991,17 @@ extension SHInputController: AVAudioPlayerDelegate {
{
{
if
sender
.
titleLabel
!.
text
!.
isEqualTo
(
"x1.5"
)
if
sender
.
titleLabel
!.
text
!.
isEqualTo
(
"x1.5"
)
{
{
self
.
audioPlayer
.
rate
=
1.5
self
.
audioPlayer
?
.
rate
=
1.5
sender
.
setTitle
(
"x2"
,
for
:
.
normal
)
sender
.
setTitle
(
"x2"
,
for
:
.
normal
)
}
}
else
if
sender
.
titleLabel
!.
text
!.
isEqualTo
(
"x2"
)
else
if
sender
.
titleLabel
!.
text
!.
isEqualTo
(
"x2"
)
{
{
self
.
audioPlayer
.
rate
=
2
self
.
audioPlayer
?
.
rate
=
2
sender
.
setTitle
(
"x1"
,
for
:
.
normal
)
sender
.
setTitle
(
"x1"
,
for
:
.
normal
)
}
}
else
if
sender
.
titleLabel
!.
text
!.
isEqualTo
(
"x1"
)
else
if
sender
.
titleLabel
!.
text
!.
isEqualTo
(
"x1"
)
{
{
self
.
audioPlayer
.
rate
=
1
self
.
audioPlayer
?
.
rate
=
1
sender
.
setTitle
(
"x1.5"
,
for
:
.
normal
)
sender
.
setTitle
(
"x1.5"
,
for
:
.
normal
)
}
}
}
}
...
@@ -811,7 +1012,7 @@ extension SHInputController: AVAudioPlayerDelegate {
...
@@ -811,7 +1012,7 @@ extension SHInputController: AVAudioPlayerDelegate {
self
.
shInputView
.
bottomView
.
playView
.
playButton
.
setImage
(
UIImage
(
named
:
"input_audio_play"
),
for
:
.
normal
)
self
.
shInputView
.
bottomView
.
playView
.
playButton
.
setImage
(
UIImage
(
named
:
"input_audio_play"
),
for
:
.
normal
)
self
.
shInputView
.
bottomView
.
progressView
.
slider
.
value
=
1
;
self
.
shInputView
.
bottomView
.
progressView
.
slider
.
value
=
1
;
self
.
shInputView
.
bottomView
.
progressView
.
timeLabel
.
text
=
self
.
viewModel
.
getTimeStringWithSeconds
(
seconds
:
self
.
dataModel
.
during
)
self
.
shInputView
.
bottomView
.
progressView
.
timeLabel
.
text
=
self
.
viewModel
.
getTimeStringWithSeconds
(
seconds
:
NSInteger
(
self
.
audioPlayer
?
.
duration
??
0
)
)
self
.
playTimer
.
suspend
()
self
.
playTimer
.
suspend
()
}
}
...
...
ShorthandMaster/Input/View/SHInputBottomView.swift
View file @
92f0fb20
...
@@ -52,6 +52,15 @@ class SHInputBottomView: UIView {
...
@@ -52,6 +52,15 @@ class SHInputBottomView: UIView {
var
directionImageView
:
UIImageView
!
var
directionImageView
:
UIImageView
!
/// 复制按钮
var
copyButton
:
UIButton
!
/// 分享按钮
var
shareButton
:
UIButton
!
/// 是否为编辑状态
var
isEdited
:
Bool
=
Bool
()
/// 计时器控制小红点闪烁
/// 计时器控制小红点闪烁
let
timer
=
DispatchSource
.
makeTimerSource
(
flags
:
[],
queue
:
DispatchQueue
.
global
())
let
timer
=
DispatchSource
.
makeTimerSource
(
flags
:
[],
queue
:
DispatchQueue
.
global
())
...
@@ -61,6 +70,8 @@ class SHInputBottomView: UIView {
...
@@ -61,6 +70,8 @@ class SHInputBottomView: UIView {
{
{
super
.
init
(
frame
:
frame
)
super
.
init
(
frame
:
frame
)
self
.
isEdited
=
isEdited
self
.
backgroundColor
=
UIColor
.
white
self
.
backgroundColor
=
UIColor
.
white
self
.
layer
.
masksToBounds
=
true
self
.
layer
.
masksToBounds
=
true
...
@@ -165,22 +176,36 @@ class SHInputBottomView: UIView {
...
@@ -165,22 +176,36 @@ class SHInputBottomView: UIView {
// 录制结束播放控件
// 录制结束播放控件
self
.
playView
=
SHInputAudioPlayView
()
self
.
playView
=
SHInputAudioPlayView
()
self
.
addSubview
(
self
.
playView
)
self
.
addSubview
(
self
.
playView
)
self
.
playView
.
isHidden
=
true
self
.
playView
.
isHidden
=
!
self
.
isEdited
// 播放进度条
// 播放进度条
self
.
progressView
=
SHInputProgressView
()
self
.
progressView
=
SHInputProgressView
()
self
.
addSubview
(
self
.
progressView
)
self
.
addSubview
(
self
.
progressView
)
self
.
progressView
.
alpha
=
0
;
self
.
progressView
.
alpha
=
self
.
isEdited
?
1
:
0
;
// 键盘按钮
// 键盘按钮
self
.
keyboardButton
=
UIButton
(
type
:
UIButton
.
ButtonType
.
custom
)
self
.
keyboardButton
=
UIButton
(
type
:
UIButton
.
ButtonType
.
custom
)
self
.
keyboardButton
.
setImage
(
UIImage
(
named
:
"input_keyboard"
),
for
:
UIControl
.
State
.
normal
)
self
.
keyboardButton
.
setImage
(
UIImage
(
named
:
"input_keyboard"
),
for
:
UIControl
.
State
.
normal
)
self
.
addSubview
(
self
.
keyboardButton
)
self
.
addSubview
(
self
.
keyboardButton
)
self
.
keyboardButton
.
isHidden
=
self
.
isEdited
// 箭头图片
// 箭头图片
self
.
directionImageView
=
UIImageView
()
self
.
directionImageView
=
UIImageView
()
self
.
directionImageView
.
image
=
UIImage
(
named
:
"input_down"
)
self
.
directionImageView
.
image
=
UIImage
(
named
:
"input_down"
)
self
.
addSubview
(
self
.
directionImageView
)
self
.
addSubview
(
self
.
directionImageView
)
self
.
directionImageView
.
isHidden
=
self
.
isEdited
// 复制按钮
self
.
copyButton
=
UIButton
(
type
:
.
custom
)
self
.
copyButton
.
setImage
(
UIImage
(
named
:
"input_copy"
),
for
:
.
normal
)
self
.
addSubview
(
self
.
copyButton
)
self
.
copyButton
.
isHidden
=
!
self
.
isEdited
// 分享按钮
self
.
shareButton
=
UIButton
(
type
:
.
custom
)
self
.
shareButton
.
setImage
(
UIImage
(
named
:
"input_share"
),
for
:
.
normal
)
self
.
addSubview
(
self
.
shareButton
)
self
.
shareButton
.
isHidden
=
!
self
.
isEdited
}
}
// MARK: - 控件位置
// MARK: - 控件位置
...
@@ -188,6 +213,51 @@ class SHInputBottomView: UIView {
...
@@ -188,6 +213,51 @@ class SHInputBottomView: UIView {
func
setUpEditedSUbviewsLocation
()
func
setUpEditedSUbviewsLocation
()
{
{
self
.
line
.
mas_makeConstraints
{
(
make
)
in
make
?
.
top
.
left
()?
.
right
()?
.
mas_equalTo
()(
0
)
make
?
.
height
.
mas_equalTo
()(
1
)
}
self
.
progressView
.
mas_makeConstraints
{
(
make
)
in
make
?
.
top
.
left
()?
.
right
()?
.
mas_equalTo
()(
self
)
make
?
.
height
.
mas_equalTo
()(
50
)
}
self
.
playView
.
mas_makeConstraints
{
(
make
)
in
make
?
.
bottom
.
mas_equalTo
()(
-
SafeAreaBottomHeight
()
-
10
)
make
?
.
left
.
mas_equalTo
()(
20
)
make
?
.
size
.
mas_equalTo
()(
CGSize
(
width
:
160
,
height
:
30
))
}
self
.
shareButton
.
mas_makeConstraints
{
(
make
)
in
make
?
.
right
.
mas_equalTo
()(
-
10
)
make
?
.
bottom
.
mas_equalTo
()(
-
SafeAreaBottomHeight
())
make
?
.
width
.
height
()?
.
mas_equalTo
()(
28
+
10
*
2
)
}
self
.
copyButton
.
mas_makeConstraints
{
(
make
)
in
make
?
.
right
.
equalTo
()(
self
.
shareButton
.
mas_left
)?
.
offset
()(
5
)
make
?
.
bottom
.
equalTo
()(
self
.
shareButton
)
make
?
.
size
.
equalTo
()(
self
.
shareButton
)
}
self
.
imageButton
.
mas_makeConstraints
{
(
make
)
in
make
?
.
right
.
equalTo
()(
self
.
copyButton
.
mas_left
)?
.
offset
()(
5
)
make
?
.
bottom
.
equalTo
()(
self
.
shareButton
)
make
?
.
size
.
equalTo
()(
self
.
shareButton
)
}
}
}
// MARK: 新增时的控件位置
// MARK: 新增时的控件位置
...
@@ -336,7 +406,6 @@ class SHInputBottomView: UIView {
...
@@ -336,7 +406,6 @@ class SHInputBottomView: UIView {
timer
.
setEventHandler
{
timer
.
setEventHandler
{
DispatchQueue
.
main
.
sync
{
DispatchQueue
.
main
.
sync
{
print
(
"在集市"
)
self
.
audioTimePointView
.
isHidden
=
!
self
.
audioTimePointView
.
isHidden
self
.
audioTimePointView
.
isHidden
=
!
self
.
audioTimePointView
.
isHidden
}
}
...
...
ShorthandMaster/Input/View/SHInputView.swift
View file @
92f0fb20
...
@@ -16,6 +16,7 @@ class SHInputView: UIView {
...
@@ -16,6 +16,7 @@ class SHInputView: UIView {
var
bottomView
:
SHInputBottomView
!
var
bottomView
:
SHInputBottomView
!
/// 是否为编辑状态
var
isEdited
:
Bool
=
Bool
()
var
isEdited
:
Bool
=
Bool
()
...
@@ -89,7 +90,7 @@ class SHInputView: UIView {
...
@@ -89,7 +90,7 @@ class SHInputView: UIView {
self
.
bottomView
.
mas_makeConstraints
{
(
make
)
in
self
.
bottomView
.
mas_makeConstraints
{
(
make
)
in
make
?
.
left
.
right
()?
.
bottom
()
.
mas_equalTo
()(
0
)
make
?
.
left
.
right
()?
.
bottom
()
.
mas_equalTo
()(
0
)
make
?
.
height
.
mas_equalTo
()(
50
+
SafeAreaBottomHeight
());
make
?
.
height
.
mas_equalTo
()(
(
self
.
isEdited
?
100
:
50
)
+
SafeAreaBottomHeight
());
}
}
}
}
...
...
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