| | |
| | | return collection |
| | | }() |
| | | |
| | | private var voicePlayer = VoicePlayer.share() |
| | | |
| | | required init(page:Int,listen4Model:Listen4Model){ |
| | | super.init(nibName: nil, bundle: nil) |
| | | self.page = page |
| | | self.listen4Model = listen4Model |
| | | self.listen4Model.data.shuffle() |
| | | } |
| | | |
| | | required init?(coder: NSCoder) { |
| | | fatalError("init(coder:) has not been implemented") |
| | | } |
| | | |
| | | func restore(){ |
| | | |
| | | answerCount = 0 |
| | | answerIndex = nil |
| | | for subView in view.subviews{ |
| | | if subView is Lesson_4_AnswerView{ |
| | | subView.removeFromSuperview() |
| | | } |
| | | } |
| | | |
| | | setUI() |
| | | collectionView.reloadData() |
| | | } |
| | | |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | |
| | | VoicePlayer.share().playEnd { |
| | | print("播放完成") |
| | | } |
| | | } |
| | | |
| | | override func viewDidAppear(_ animated: Bool) { |
| | | super.viewDidAppear(animated) |
| | | voicePlayer.delegate = self |
| | | } |
| | | |
| | | override func viewDidDisappear(_ animated: Bool) { |
| | | super.viewDidDisappear(animated) |
| | | voicePlayer.delegate = nil |
| | | } |
| | | |
| | | |
| | | override func setUI() { |
| | | super.setUI() |
| | | |
| | | collectionView.delegate = self |
| | | collectionView.dataSource = self |
| | | collectionView.showsVerticalScrollIndicator = false |
| | | collectionView.backgroundColor = .clear |
| | | view.addSubview(collectionView) |
| | | if !view.subviews.contains(collectionView){ |
| | | collectionView.delegate = self |
| | | collectionView.dataSource = self |
| | | collectionView.showsVerticalScrollIndicator = false |
| | | collectionView.backgroundColor = .clear |
| | | view.addSubview(collectionView) |
| | | } |
| | | |
| | | collectionView.snp.makeConstraints { make in |
| | | make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top).offset(0) |
| | | make.left.equalTo(164) |
| | |
| | | alertError(msg: "请先听题");return |
| | | } |
| | | |
| | | stackView.removeArrangedSubviews() |
| | | for v in stackView.subviews{ |
| | | v.removeFromSuperview() |
| | | } |
| | | |
| | | if !view.subviews.contains(stackView){ |
| | | view.addSubview(stackView) |
| | |
| | | } |
| | | |
| | | |
| | | let answerId = listen4Model.data[viewModel.selectIndex.value!.section].answerSubject |
| | | let answerId = listen4Model.data[viewModel.selectIndex.value!.section].subject |
| | | var tempVoiceArray = [String]() |
| | | for v in listen4Model.data[viewModel.selectIndex.value!.section].subjectList{ |
| | | if v.id == answerId{ |
| | |
| | | |
| | | var answerModel:Listen1SubModel? |
| | | for (index,v) in (listen4Model.data[viewModel.selectIndex.value!.section].subjectList).enumerated(){ |
| | | if v.id == listen4Model.data[viewModel.selectIndex.value!.section].answerSubject{ |
| | | if v.id == listen4Model.data[viewModel.selectIndex.value!.section].subject{ |
| | | answerModel = v |
| | | }else{ |
| | | answerIndex = IndexPath(row: index, section: viewModel.selectIndex.value!.section) |
| | | } |
| | | } |
| | |
| | | answerType = .fail |
| | | rootViewModel.errorNum += 1 |
| | | } |
| | | VoicePlayer.share().playerEnd() |
| | | voicePlayer.playerEnd() |
| | | |
| | | switch answerType { |
| | | case .success: |
| | |
| | | copyView.frame = CGRect(origin: newRect1.origin, size: CGSize(width: 152, height: 52)) |
| | | } completion: { _ in |
| | | self.viewModel.selectIndex.accept(nil) |
| | | self.stackView.removeArrangedSubviews() |
| | | for v in self.stackView.subviews{ |
| | | v.removeFromSuperview() |
| | | } |
| | | self.stackView.layoutIfNeeded() |
| | | |
| | | //回答完成,下一答题 |
| | | if self.answerCount == 2{ |
| | | self.rootViewModel.answerItems[self.page] = self.listen4Model |
| | | VoicePlayer.share().playerEnd() |
| | | NotificationCenter.default.post(name: NextLession_Noti, object: nil);return |
| | | self.voicePlayer.playerEnd() |
| | | NotificationCenter.default.post(name: NextLession_Noti, object: nil) |
| | | self.voicePlayer.playerEnd() |
| | | return |
| | | } |
| | | } |
| | | } |
| | |
| | | func numberOfSections(in collectionView: UICollectionView) -> Int { |
| | | return listen4Model.data.count |
| | | } |
| | | } |
| | | |
| | | extension HomeListenFight_lesson_4_VC:VoicePlayerDelegate{ |
| | | func playComplete() { |
| | | |
| | | } |
| | | |
| | | func playing() { |
| | | |
| | | } |
| | | } |