无故事王国
4 天以前 510991a68acc59e22602d95582e3b1cabdd093c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//
//  HomeListenStory_2_VC.swift
//  DolphinEnglishLearnStudent
//
//  Created by 无故事王国 on 2024/5/30.
//
 
import UIKit
 
class HomeListenStory_2_VC: BaseVC {
 
                var rootViewModel:HomeListenFightViewModel!
 
                private var viewModel = FightAnswerViewModel()
                private var listen1Model:Listen1Model!
                private var page:Int!
                private var voicePlayer = VoicePlayer.share()
                private(set) var isPlayEnd = false
                private lazy var stackView:UIStackView = {
                                let stackView = UIStackView()
                                stackView.spacing = 78
                                stackView.distribution = .equalSpacing
                                return stackView
                }()
 
                private lazy var collectionView:UICollectionView = {
                                let flowLayout = UICollectionViewFlowLayout()
                                let w = (JQ_ScreenW - 235 * 2)
                                flowLayout.itemSize = CGSize(width: w, height: w * 0.6666)
                                flowLayout.minimumInteritemSpacing = 0
                                flowLayout.scrollDirection = .vertical
                                let collection = UICollectionView(frame: .zero, collectionViewLayout: flowLayout)
                                collection.contentInset = UIEdgeInsets(top: 130, left: 0, bottom: 0, right: 0)
                                collection.register(UINib(nibName: "SimpleImageCCell", bundle: nil), forCellWithReuseIdentifier: "_SimpleImageCCell")
                                return collection
                }()
 
                required init(page:Int,listen1Model:Listen1Model){
                                super.init(nibName: nil, bundle: nil)
                                self.page = page
                                self.listen1Model = listen1Model
                }
 
                required init?(coder: NSCoder) {
                                fatalError("init(coder:) has not been implemented")
                }
 
                override func viewDidAppear(_ animated: Bool) {
                                super.viewDidAppear(animated)
                                voicePlayer.delegate = self
                                restore()
                }
 
                override func viewDidDisappear(_ animated: Bool) {
                                super.viewDidDisappear(animated)
                                voicePlayer.delegate = nil
                                voicePlayer.playerInterrupt()
                }
 
 
                override func setUI() {
                                super.setUI()
 
                                viewModel.selectIndex.accept(IndexPath(row: 0, section: 0))
                                collectionView.delegate = self
                                collectionView.dataSource = self
                                collectionView.showsVerticalScrollIndicator = false
                                collectionView.backgroundColor = .clear
                                collectionView.jq_addShadows(shadowColor: UIColor.black.withAlphaComponent(0.1), corner: 8, radius: 10, offset: CGSize(width: 0, height: 2), opacity: 1)
                                collectionView.isScrollEnabled = false
                                view.addSubview(collectionView)
                                collectionView.snp.makeConstraints { make in
                                                make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top).offset(0)
                                                make.left.equalTo(164)
                                                make.width.equalTo(JQ_ScreenW - 164 * 2)
                                                make.bottom.equalToSuperview()
                                }
 
                                view.addSubview(stackView)
                                stackView.snp.makeConstraints { make in
                                                make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top).offset(24)
                                                make.centerX.equalToSuperview()
                                                make.height.equalTo(52)
                                                make.width.equalTo(159)
                                }
 
                                for subV in stackView.arrangedSubviews{
                                                subV.removeFromSuperview()
                                }
 
                                let handleView = VoiceHandleView()
                                handleView.playUrl = listen1Model.storyList[page].correct
                                handleView.snp.makeConstraints { make in
                                                make.height.equalTo(52)
                                                make.width.greaterThanOrEqualTo(221)
                                }
                                stackView.addArrangedSubview(handleView)
 
                                DispatchQueue.main.asyncAfter(wallDeadline: .now()+2){
                                                handleView.playingAction()
                                }
                }
 
                func restore(){
                                isPlayEnd = false
                                viewModel.answerType.accept(.none)
                                setUI()
                                collectionView.reloadData()
                }
}
 
extension HomeListenStory_2_VC:UICollectionViewDelegate{}
 
extension HomeListenStory_2_VC:UICollectionViewDelegateFlowLayout{}
 
extension HomeListenStory_2_VC:UICollectionViewDataSource{
                func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
                                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_SimpleImageCCell", for: indexPath) as! SimpleImageCCell
                                let m = listen1Model.storyList[page]
                                cell.img_cover.sd_setImage(with: URL(string: m.img))
                                cell.jq_cornerRadius = 10
                                return cell
                }
 
                func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
                                return 1
                }
 
                func numberOfSections(in collectionView: UICollectionView) -> Int {
                                return 1
                }
}
 
extension HomeListenStory_2_VC:VoicePlayerDelegate{
                func playComplete() {
                                isPlayEnd = true
                                view.isUserInteractionEnabled = true
                }
 
                func playing() {
                                view.isUserInteractionEnabled = false
                }
}