|
@@ -138,19 +138,32 @@ class PQSelecteMusicView: UIView {
|
|
|
//插入数据
|
|
|
func insertSearchMusic(model:PQVoiceModel) {
|
|
|
|
|
|
- for oldModel in searchMusiceDatas {
|
|
|
+ for oldModel in musicDatas {
|
|
|
oldModel.voiceStatue = .isNormal
|
|
|
}
|
|
|
-
|
|
|
- model.voiceStatue = .isSelected
|
|
|
- searchMusiceDatas.insert(model, at: 0)
|
|
|
-
|
|
|
- //有搜索的数据
|
|
|
- if(currentSelectTag?.tagId == 425){
|
|
|
- musicDatas.insert(contentsOf: searchMusiceDatas, at: 0)
|
|
|
+
|
|
|
+ let musicIndex = musicDatas.firstIndex(where: { (music) -> Bool in
|
|
|
+ (music.musicId == model.musicId)
|
|
|
+ })
|
|
|
+ if(musicIndex == nil){
|
|
|
+ model.voiceStatue = .isSelected
|
|
|
+ searchMusiceDatas.insert(model, at: 0)
|
|
|
+ //有搜索的数据
|
|
|
+ if(currentSelectTag?.tagId == 425){
|
|
|
+ musicDatas.insert(model, at: 0)
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ musicDatas[musicIndex!].voiceStatue = .isSelected
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
selectMusicCollection.reloadData()
|
|
|
+
|
|
|
+ //划动到选择的音乐位置
|
|
|
+ if(musicIndex != nil){
|
|
|
+ selectMusicCollection.scrollToItem(at: IndexPath(row: musicIndex!, section: 0), at: .centeredHorizontally, animated: true)
|
|
|
+ }else{
|
|
|
+ selectMusicCollection.scrollToItem(at: IndexPath(row: 0, section: 0), at: .centeredHorizontally, animated: true)
|
|
|
+ }
|
|
|
}
|
|
|
func autolayout() {
|
|
|
categoryCollection.snp.makeConstraints { make in
|