| | |
| | | |
| | | }() |
| | | |
| | | private let view_class_title = UIView() |
| | | |
| | | private lazy var label_hint:UILabel = { |
| | | let label = UILabel() |
| | | label.textColor = UIColor(hexStr: "#EE1111") |
| | |
| | | |
| | | private lazy var collectionView:UICollectionView = { |
| | | let flowLayout = UICollectionViewFlowLayout() |
| | | let w = (JQ_ScreenW - 35 * 2 - 12) / 4.0 |
| | | flowLayout.itemSize = CGSize(width: w, height: w * 0.73) |
| | | flowLayout.minimumInteritemSpacing = 3 |
| | | flowLayout.minimumLineSpacing = 13 |
| | | flowLayout.minimumLineSpacing = 3 |
| | | flowLayout.scrollDirection = .vertical |
| | | let collection = UICollectionView(frame: .zero, collectionViewLayout: flowLayout) |
| | | collection.contentInset = UIEdgeInsets(top: 0, left: 35, bottom: 0, right: 35) |
| | |
| | | super.viewDidLoad() |
| | | |
| | | if listen1Model != nil{ |
| | | times = listen1Model?.data?.time ?? 10 |
| | | times = (listen1Model?.data?.time ?? 10) + 1 |
| | | collectionView.reloadData() |
| | | label_hint.isHidden = false |
| | | label_hint.text = "准备听题" |
| | |
| | | override func setUI() { |
| | | super.setUI() |
| | | |
| | | let view_class_title = UIView() |
| | | |
| | | view_class_title.jq_cornerRadius = 16 |
| | | view_class_title.backgroundColor = UIColor(hexStr: "#FBCF0F") |
| | | view.addSubview(view_class_title) |
| | |
| | | view.layoutIfNeeded() |
| | | } |
| | | |
| | | override func viewDidLayoutSubviews() { |
| | | super.viewDidLayoutSubviews() |
| | | if let res = Array<Any>.CalmulateCell(listen1Model.subjectList.count){ |
| | | let layout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout |
| | | let w = (JQ_ScreenW - (collectionView.contentInset.left * 2) - (CGFloat(res.0) - 1.0) * layout.minimumInteritemSpacing) / Double(res.0) |
| | | let h = (collectionView.frame.height - (layout.minimumLineSpacing * (Double(res.1) - 1.0))) / Double(res.1) |
| | | |
| | | if layout.itemSize != CGSize(width: w, height: h){ |
| | | layout.itemSize = CGSize(width: w, height: h) |
| | | collectionView.reloadData() |
| | | } |
| | | } |
| | | } |
| | | |
| | | func startTimer(){ |
| | | if timer == nil{ |
| | |
| | | answerSet.remove(c) |
| | | } |
| | | currentAnswer = answerSet.randomElement() //随机 |
| | | times = listen1Model?.data?.time ?? 0 |
| | | times = (listen1Model?.data?.time ?? 0) + 1 |
| | | timer?.fireDate = .distantPast |
| | | totalCount += 1 |
| | | rootViewModel.errorNum += 1 |
| | |
| | | } |
| | | switch answerType { |
| | | case .success: |
| | | timer?.fireDate = .distantFuture |
| | | viewModel.answerType.accept(.success) |
| | | collectionView.reloadData() |
| | | if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_ListenFight_Game_CCell", for: viewModel.selectIndex.value!) as? ListenFight_Game_CCell{ |
| | |
| | | } completion: { _ in |
| | | DispatchQueue.main.asyncAfter(deadline: .now()+0.5) { |
| | | self.voicePlayer.playerAt(url: self.currentAnswer?.correct) |
| | | self.timer?.fireDate = .distantFuture |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | collectionView.reloadData() |
| | | DispatchQueue.main.asyncAfter(deadline: .now()+3) { |
| | | self.times = self.listen1Model?.data?.time ?? 10 |
| | | self.times = (self.listen1Model?.data?.time ?? 10) + 1 |
| | | self.currentAnswer = self.answerSet.randomElement() |
| | | } |
| | | case .none: |
| | |
| | | |
| | | private func completeQuestion(){ |
| | | print("答题完成") |
| | | self.label_hint.text = "答题完成" |
| | | self.label_hint.text = "已完成全部答题" |
| | | self.label_hint.snp.makeConstraints { make in |
| | | make.centerX.equalToSuperview() |
| | | make.centerY.equalTo(view_class_title) |
| | | make.height.equalTo(20) |
| | | } |
| | | |
| | | view_class_title.isHidden = true |
| | | view_studyHandleView.isHidden = true |
| | | |
| | | self.timer?.invalidate() |
| | | self.rootViewModel.answerItems[0] = self.listen1Model |
| | | NotificationCenter.default.post(name: NextLession_Noti, object: ["gameId":listen1Model.data!.id,"gameIntegral":listen1Model.data!.integral]) |
| | | NotificationCenter.default.post(name: NextLession_Noti, object: ["gameId":listen1Model.data!.id,"gameIntegral":listen1Model.data!.integral,"complete":true]) |
| | | } |
| | | } |
| | | |
| | | extension HomeListenGame_1_VC:UICollectionViewDelegate{ |
| | | func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { |
| | | let model = listen1Model!.subjectList[indexPath.row] |
| | | if answerSet.contains(model){ |
| | | // _ = listen1Model!.subjectList[indexPath.row] |
| | | viewModel.selectIndex.accept(indexPath) |
| | | answerQuestion() |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | extension HomeListenGame_1_VC:VoicePlayerDelegate{ |
| | | func playComplete() { |
| | | view.isUserInteractionEnabled = true |
| | | |
| | | //防止再次播放时,误操作计算了正确率 |
| | | if viewModel.answerType.value == .none{ |
| | | view.isUserInteractionEnabled = true |
| | | } |
| | | |
| | | timer?.fireDate = .distantPast ////播放中,恢复计时 |
| | | |
| | | view_studyHandleView.resetView() |
| | | |
| | | self.label_hint.text = "准备听题" |
| | | |
| | | if viewModel.answerType.value == .success{ |
| | | self.label_hint.text = "准备请听下一题" |
| | | timer?.fireDate = .distantFuture |
| | | DispatchQueue.main.asyncAfter(deadline: .now()+3) { |
| | | self.times = self.listen1Model?.data?.time ?? 10 |
| | | self.times = (self.listen1Model?.data?.time ?? 10) + 1 |
| | | self.totalCount += 1 |
| | | self.rootViewModel.correctNum += 1 |
| | | self.label_class.text = "\(self.totalCount)" |
| | | self.answerSet.remove(self.currentAnswer!) |
| | | |
| | | if let currentA = self.currentAnswer{ |
| | | self.answerSet.remove(currentA) |
| | | } |
| | | |
| | | self.currentAnswer = self.answerSet.randomElement() |
| | | self.viewModel.answerType.accept(.none) |
| | | print("--->下一题:\(self.currentAnswer?.id ?? 0) 剩余\(self.answerSet.count) 计数:\(self.totalCount)") |
| | |
| | | func playing() { |
| | | view.isUserInteractionEnabled = false |
| | | view_studyHandleView.playing() |
| | | timer?.fireDate = .distantFuture //播放中,暂停计时 |
| | | label_hint.text = "播放中" |
| | | } |
| | | |
| | | } |