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
4f12f443
Commit
4f12f443
authored
Sep 29, 2020
by
lmj_521aiau@163.com
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'branch_1.0.1' of gitlab.huolea.com:lmi/shorthandmaster into branch_1.0.1
parents
87dd31b4
1daaf8c8
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
257 additions
and
68 deletions
+257
-68
SHInputController.swift
ShorthandMaster/Input/Controller/SHInputController.swift
+253
-64
SHInputAudioPlayView.swift
ShorthandMaster/Input/View/SHInputAudioPlayView.swift
+1
-1
SHInputBottomView.swift
ShorthandMaster/Input/View/SHInputBottomView.swift
+1
-1
SHInputView.swift
ShorthandMaster/Input/View/SHInputView.swift
+2
-2
No files found.
ShorthandMaster/Input/Controller/SHInputController.swift
View file @
4f12f443
...
...
@@ -37,6 +37,13 @@ class SHInputController: SHBaseViewController
/// 播放计时器
let
playTimer
=
DispatchSource
.
makeTimerSource
(
flags
:
[],
queue
:
DispatchQueue
.
global
())
/// 播放计算器是否正在计时
var
playTimerCounting
=
false
/// 播放完成
var
playFinished
=
false
/// 是否是编辑
var
isEdited
=
false
...
...
@@ -81,19 +88,25 @@ class SHInputController: SHBaseViewController
}
// 初始化播放计时器
self
.
playTimer
.
schedule
(
deadline
:
.
now
(),
repeating
:
0.03
)
self
.
playTimer
.
setEventHandler
{
DispatchQueue
.
main
.
sync
{
self
.
initPlayTimer
()
self
.
shInputView
.
bottomView
.
progressView
.
slider
.
value
=
Float
(
self
.
audioPlayer
?
.
currentTime
??
0
)
/
Float
(
self
.
audioPlayer
?
.
duration
??
0
)
self
.
addSubviews
(
)
self
.
shInputView
.
bottomView
.
progressView
.
timeLabel
.
text
=
self
.
viewModel
.
getTimeStringWithSeconds
(
seconds
:
NSInteger
(
self
.
audioPlayer
?
.
currentTime
??
0
)
)
self
.
setUpSubviewsLocation
(
)
}
override
func
viewWillAppear
(
_
animated
:
Bool
)
{
super
.
viewWillAppear
(
animated
)
// 禁用右滑返回
self
.
navigationController
?
.
interactivePopGestureRecognizer
?
.
isEnabled
=
false
}
self
.
addSubviews
()
override
func
viewWillDisappear
(
_
animated
:
Bool
)
{
super
.
viewWillDisappear
(
animated
)
self
.
setUpSubviewsLocation
()
// 恢复右滑返回
self
.
navigationController
?
.
interactivePopGestureRecognizer
?
.
isEnabled
=
true
}
override
func
viewDidDisappear
(
_
animated
:
Bool
)
{
...
...
@@ -195,7 +208,23 @@ class SHInputController: SHBaseViewController
// MARK: 点击navigationBar左侧按钮
override
func
goback
()
{
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
)
}
// MARK: 点击navigationBar右侧按钮
...
...
@@ -394,6 +423,20 @@ class SHInputController: SHBaseViewController
extension
SHInputController
:
UITextViewDelegate
,
SHInputTextViewDelegate
{
// MARK: - UITextView代理
// MARK: 滑动
func
scrollViewDidScroll
(
_
scrollView
:
UIScrollView
)
{
let
vel
=
scrollView
.
panGestureRecognizer
.
velocity
(
in
:
scrollView
)
if
vel
.
y
>
20
{
if
self
.
shInputView
.
textView
.
canResignFirstResponder
{
self
.
shInputView
.
textView
.
resignFirstResponder
()
}
}
}
// MARK: 文字发生了变化
func
textViewDidChange
(
_
textView
:
UITextView
)
{
...
...
@@ -768,8 +811,69 @@ extension SHInputController: UIImagePickerControllerDelegate, UINavigationContro
// MARK: - 录音
extension
SHInputController
{
// MARK: 点击添加录音按钮
// MARK: 点击添加录音按钮
, 先判断麦克风权限
@objc
func
didSelectedAddAudioButton
(
sender
:
SHInputAudioButton
)
{
let
status
:
AVAuthorizationStatus
=
AVCaptureDevice
.
authorizationStatus
(
for
:
.
audio
)
switch
status
{
// MARK: 此应用程序未被授权, 可能是家长控制权限。
case
AVAuthorizationStatus
.
restricted
:
let
alert
=
UIAlertController
(
title
:
nil
,
message
:
"此应用程序未被授权, 可能是家长控制权限。"
,
preferredStyle
:
UIAlertController
.
Style
.
alert
)
let
sureAction
=
UIAlertAction
(
title
:
"确定"
,
style
:
UIAlertAction
.
Style
.
default
,
handler
:
nil
)
alert
.
addAction
(
sureAction
)
self
.
present
(
alert
,
animated
:
true
,
completion
:
nil
)
break
// MARK: 用户拒绝当前应用访问麦克风
case
AVAuthorizationStatus
.
denied
:
let
alert
=
UIAlertController
(
title
:
"此功能需要麦克风授权"
,
message
:
"请您在设置系统中打开授权开关"
,
preferredStyle
:
UIAlertController
.
Style
.
alert
)
let
cancelAction
=
UIAlertAction
(
title
:
"取消"
,
style
:
UIAlertAction
.
Style
.
cancel
,
handler
:
nil
)
alert
.
addAction
(
cancelAction
)
let
settingAction
=
UIAlertAction
(
title
:
"前往设置"
,
style
:
UIAlertAction
.
Style
.
default
)
{
(
action
)
in
UIApplication
.
shared
.
open
(
URL
(
string
:
UIApplication
.
openSettingsURLString
)
!
,
options
:
[:],
completionHandler
:
nil
)
}
alert
.
addAction
(
settingAction
)
self
.
present
(
alert
,
animated
:
true
,
completion
:
nil
)
break
// MARK: 用户允许当前应用访问麦克风
case
AVAuthorizationStatus
.
authorized
:
if
UIImagePickerController
.
isSourceTypeAvailable
(
UIImagePickerController
.
SourceType
.
camera
)
{
self
.
beginAddAudio
()
}
break
// MARK: 用户还没有做出选择
case
AVAuthorizationStatus
.
notDetermined
:
AVCaptureDevice
.
requestAccess
(
for
:
.
audio
)
{
(
flag
)
in
if
flag
{
DispatchQueue
.
main
.
async
{
self
.
beginAddAudio
()
}
}
}
break
default
:
break
}
}
// MARK: 开始录音
func
beginAddAudio
()
{
self
.
shInputView
.
bottomView
.
addAudioButton
.
isHidden
=
true
self
.
shInputView
.
bottomView
.
audioTimeBgView
.
isHidden
=
false
...
...
@@ -836,6 +940,16 @@ extension SHInputController
// MARK: 点击结束录制按钮
@objc
func
didSelectedStopAudioButton
(
sender
:
SHInputAudioButton
)
{
recorder_mp3
.
pause
()
self
.
timer
.
suspend
()
self
.
shInputView
.
bottomView
.
audioTimePointViewAnimation
(
animation
:
false
)
let
alert
=
UIAlertController
(
title
:
"提示"
,
message
:
"结束录音后,不能再进行续录。"
,
preferredStyle
:
.
alert
)
let
leftAction
=
UIAlertAction
(
title
:
"结束录音"
,
style
:
.
destructive
)
{
(
action
)
in
self
.
shInputView
.
bottomView
.
addAudioButton
.
isHidden
=
true
self
.
shInputView
.
bottomView
.
audioTimeBgView
.
isHidden
=
true
self
.
shInputView
.
bottomView
.
pauseAudioButton
.
isHidden
=
true
...
...
@@ -844,7 +958,7 @@ extension SHInputController
self
.
shInputView
.
bottomView
.
playView
.
isHidden
=
false
self
.
shInputView
.
bottomView
.
setUpSubviewsLocation
()
recorder_mp3
.
stop
()
self
.
recorder_mp3
.
stop
()
self
.
timer
.
cancel
()
self
.
shInputView
.
bottomView
.
timer
.
cancel
()
...
...
@@ -868,12 +982,68 @@ extension SHInputController
self
.
shInputView
.
bottomView
.
superview
!.
layoutIfNeeded
()
}
}
alert
.
addAction
(
leftAction
)
let
rightAction
=
UIAlertAction
(
title
:
"暂不结束"
,
style
:
.
default
)
{
(
action
)
in
}
alert
.
addAction
(
rightAction
)
self
.
present
(
alert
,
animated
:
true
,
completion
:
nil
)
}
}
// MARK: - 播放
extension
SHInputController
:
AVAudioPlayerDelegate
{
// MARK: 初始化播放计时器
func
initPlayTimer
()
{
self
.
playTimer
.
schedule
(
deadline
:
.
now
(),
repeating
:
0.03
)
self
.
playTimer
.
setEventHandler
{
DispatchQueue
.
main
.
sync
{
print
(
"计时中"
+
String
(
self
.
audioPlayer
?
.
currentTime
??
0
))
if
Float
(
self
.
audioPlayer
?
.
duration
??
0
)
-
Float
(
self
.
audioPlayer
?
.
currentTime
??
0
)
<=
0.1
{
self
.
playFinished
=
true
}
if
!
self
.
playFinished
{
self
.
shInputView
.
bottomView
.
progressView
.
slider
.
value
=
min
(
Float
(
self
.
audioPlayer
?
.
currentTime
??
0
)
/
Float
(
self
.
audioPlayer
?
.
duration
??
0
),
1
)
self
.
shInputView
.
bottomView
.
progressView
.
timeLabel
.
text
=
self
.
viewModel
.
getTimeStringWithSeconds
(
seconds
:
NSInteger
(
self
.
audioPlayer
?
.
currentTime
??
0
))
}
}
}
}
// MARK: 播放计时器开始计时
func
startPlayTimer
()
{
if
!
playTimerCounting
{
self
.
playTimer
.
resume
()
playTimerCounting
=
true
}
}
// MARK: 播放计时器暂停计时
func
pausePlayTimer
()
{
if
playTimerCounting
{
self
.
playTimer
.
suspend
()
playTimerCounting
=
false
}
}
// MARK: 初始化播放器
func
initPlayer
()
{
...
...
@@ -894,6 +1064,8 @@ extension SHInputController: AVAudioPlayerDelegate {
self
.
audioPlayer
?
.
enableRate
=
true
// 允许变速播放
self
.
audioPlayer
?
.
delegate
=
self
self
.
dataModel
.
during
=
NSInteger
(
self
.
audioPlayer
?
.
duration
??
0
)
// 后台播放
let
session
=
AVAudioSession
.
sharedInstance
()
try
?
session
.
setCategory
(
AVAudioSession
.
Category
.
playAndRecord
,
options
:
.
defaultToSpeaker
)
...
...
@@ -907,17 +1079,24 @@ extension SHInputController: AVAudioPlayerDelegate {
// 暂停
self
.
audioPlayer
?
.
pause
()
self
.
p
layTimer
.
suspend
()
self
.
p
ausePlayTimer
()
sender
.
setImage
(
UIImage
(
named
:
"input_audio_play"
),
for
:
.
normal
)
}
else
{
// 播放
self
.
playTimer
.
resume
()
if
self
.
playFinished
{
self
.
audioPlayer
?
.
currentTime
=
0
;
self
.
playFinished
=
false
}
self
.
audioPlayer
?
.
play
()
self
.
startPlayTimer
()
sender
.
setImage
(
UIImage
(
named
:
"input_audio_pause"
),
for
:
.
normal
)
}
}
...
...
@@ -925,33 +1104,38 @@ extension SHInputController: AVAudioPlayerDelegate {
// MARK: 后退10s
@objc
func
didSelectedBeforeButton
(
sender
:
UIButton
)
{
// self.playTimer.suspend()
//
// self.audioPlayer.pause()
//
self
.
playFinished
=
false
self
.
audioPlayer
?
.
pause
()
self
.
pausePlayTimer
()
self
.
audioPlayer
?
.
currentTime
=
max
((
self
.
audioPlayer
?
.
currentTime
??
0
)
-
10
,
0
)
// self.playTimer.resume
()
//
// self.audioPlayer.play
()
//
// self.shInputView.bottomView.playView.playButton.setImage(UIImage(named: "input_audio_play
"), for: .normal)
self
.
audioPlayer
?
.
play
()
self
.
startPlayTimer
()
self
.
shInputView
.
bottomView
.
playView
.
playButton
.
setImage
(
UIImage
(
named
:
"input_audio_pause
"
),
for
:
.
normal
)
}
// MARK: 前进10s
@objc
func
didSelectedLaterButton
(
sender
:
UIButton
)
{
// self.playTimer.suspend()
//
// self.audioPlayer.pause()
//
self
.
audioPlayer
?
.
currentTime
=
min
((
self
.
audioPlayer
?
.
currentTime
??
0
)
+
10
,
TimeInterval
(
self
.
audioPlayer
?
.
duration
??
0
))
self
.
playFinished
=
false
// self.playTimer.resume()
//
// self.audioPlayer.play()
//
// self.shInputView.bottomView.playView.playButton.setImage(UIImage(named: "input_audio_play"), for: .normal)
self
.
audioPlayer
?
.
pause
()
self
.
pausePlayTimer
()
// 最大时间直接等于self.audioPlayer?.duration音频会从第1s重新开始播放
self
.
audioPlayer
?
.
currentTime
=
min
((
self
.
audioPlayer
?
.
currentTime
??
0
)
+
10
,
TimeInterval
(
self
.
audioPlayer
?
.
duration
??
0
)
-
0.03
)
self
.
audioPlayer
?
.
play
()
self
.
startPlayTimer
()
self
.
shInputView
.
bottomView
.
playView
.
playButton
.
setImage
(
UIImage
(
named
:
"input_audio_pause"
),
for
:
.
normal
)
}
// MARK: 开始拖动进度条
...
...
@@ -960,7 +1144,7 @@ extension SHInputController: AVAudioPlayerDelegate {
// 暂停
self
.
audioPlayer
?
.
pause
()
self
.
p
layTimer
.
suspend
()
self
.
p
ausePlayTimer
()
self
.
shInputView
.
bottomView
.
playView
.
playButton
.
setImage
(
UIImage
(
named
:
"input_audio_play"
),
for
:
.
normal
)
}
...
...
@@ -976,33 +1160,36 @@ extension SHInputController: AVAudioPlayerDelegate {
// MARK: 结束拖动进度条
@objc
func
sliderTouchEnd
(
sender
:
UISlider
)
{
// 播放
self
.
audioPlayer
?
.
currentTime
=
min
(
TimeInterval
(
Double
(
sender
.
value
)
*
Double
(
self
.
audioPlayer
?
.
duration
??
0
)),
Double
(
self
.
audioPlayer
?
.
duration
??
0
))
self
.
playFinished
=
false
self
.
playTimer
.
resume
()
// 播放
// 最大时间直接等于self.audioPlayer?.duration音频会从第1s重新开始播放
self
.
audioPlayer
?
.
currentTime
=
min
(
TimeInterval
(
Double
(
sender
.
value
)
*
Double
(
self
.
audioPlayer
?
.
duration
??
0
)),
Double
(
self
.
audioPlayer
?
.
duration
??
0
)
-
0.03
)
self
.
audioPlayer
?
.
play
()
self
.
startPlayTimer
()
self
.
shInputView
.
bottomView
.
playView
.
playButton
.
setImage
(
UIImage
(
named
:
"input_audio_pause"
),
for
:
.
normal
)
}
// MARK: 切换倍速
@objc
func
didSelectedSpeedButton
(
sender
:
UIButton
)
{
if
sender
.
titleLabel
!.
text
!.
isEqualTo
(
"x1
.5
"
)
if
sender
.
titleLabel
!.
text
!.
isEqualTo
(
"x1"
)
{
self
.
audioPlayer
?
.
rate
=
1.5
sender
.
setTitle
(
"x
2
"
,
for
:
.
normal
)
sender
.
setTitle
(
"x
1.5
"
,
for
:
.
normal
)
}
else
if
sender
.
titleLabel
!.
text
!.
isEqualTo
(
"x
2
"
)
else
if
sender
.
titleLabel
!.
text
!.
isEqualTo
(
"x
1.5
"
)
{
self
.
audioPlayer
?
.
rate
=
2
sender
.
setTitle
(
"x
1
"
,
for
:
.
normal
)
sender
.
setTitle
(
"x
2
"
,
for
:
.
normal
)
}
else
if
sender
.
titleLabel
!.
text
!.
isEqualTo
(
"x
1
"
)
else
if
sender
.
titleLabel
!.
text
!.
isEqualTo
(
"x
2
"
)
{
self
.
audioPlayer
?
.
rate
=
1
sender
.
setTitle
(
"x1
.5
"
,
for
:
.
normal
)
sender
.
setTitle
(
"x1"
,
for
:
.
normal
)
}
}
...
...
@@ -1010,10 +1197,12 @@ extension SHInputController: AVAudioPlayerDelegate {
// MARK: 播放完成
func
audioPlayerDidFinishPlaying
(
_
player
:
AVAudioPlayer
,
successfully
flag
:
Bool
)
{
print
(
"播放完成"
)
player
.
currentTime
=
player
.
duration
self
.
shInputView
.
bottomView
.
playView
.
playButton
.
setImage
(
UIImage
(
named
:
"input_audio_play"
),
for
:
.
normal
)
self
.
shInputView
.
bottomView
.
progressView
.
slider
.
value
=
1
;
self
.
shInputView
.
bottomView
.
progressView
.
timeLabel
.
text
=
self
.
viewModel
.
getTimeStringWithSeconds
(
seconds
:
NSInteger
(
self
.
audioPlayer
?
.
duration
??
0
))
self
.
p
layTimer
.
suspend
()
self
.
p
ausePlayTimer
()
}
}
ShorthandMaster/Input/View/SHInputAudioPlayView.swift
View file @
4f12f443
...
...
@@ -64,7 +64,7 @@ class SHInputAudioPlayView: UIView {
// 播放速度按钮
self
.
speedButton
=
UIButton
(
type
:
.
system
)
self
.
speedButton
.
setTitle
(
"x1
.5
"
,
for
:
.
normal
)
self
.
speedButton
.
setTitle
(
"x1"
,
for
:
.
normal
)
self
.
speedButton
.
setTitleColor
(
UIColor
(
r
:
65
,
g
:
131
,
b
:
244
),
for
:
.
normal
)
self
.
speedButton
.
titleLabel
?
.
font
=
UIFont
(
name
:
SHPingFangMedium
,
size
:
14
)
self
.
addSubview
(
self
.
speedButton
)
...
...
ShorthandMaster/Input/View/SHInputBottomView.swift
View file @
4f12f443
...
...
@@ -198,7 +198,7 @@ class SHInputBottomView: UIView {
// 箭头图片
self
.
directionImageView
=
UIImageView
()
self
.
directionImageView
.
image
=
UIImage
(
named
:
"input_
down
"
)
self
.
directionImageView
.
image
=
UIImage
(
named
:
"input_
up
"
)
self
.
addSubview
(
self
.
directionImageView
)
self
.
directionImageView
.
isHidden
=
self
.
isEdited
...
...
ShorthandMaster/Input/View/SHInputView.swift
View file @
4f12f443
...
...
@@ -103,7 +103,7 @@ class SHInputView: UIView {
// MARK: 监听键盘出现
@objc
func
keyboardWillShow
(
note
:
Notification
)
{
self
.
bottomView
.
directionImageView
.
image
=
UIImage
(
named
:
"input_
up
"
)
self
.
bottomView
.
directionImageView
.
image
=
UIImage
(
named
:
"input_
down
"
)
let
info
:
Dictionary
=
note
.
userInfo
!
as
Dictionary
let
value
=
info
[
UIResponder
.
keyboardFrameEndUserInfoKey
]
...
...
@@ -132,7 +132,7 @@ class SHInputView: UIView {
// MARK: 监听键盘消失
@objc
func
keyboardWillHide
(
note
:
Notification
)
{
self
.
bottomView
.
directionImageView
.
image
=
UIImage
(
named
:
"input_
down
"
)
self
.
bottomView
.
directionImageView
.
image
=
UIImage
(
named
:
"input_
up
"
)
weak
var
weakSelf
=
self
...
...
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