| | |
| | | override func viewDidDisappear(_ animated: Bool) { |
| | | super.viewDidDisappear(animated) |
| | | timer?.invalidate() |
| | | timer = nil |
| | | voicePlayer.delegate = nil |
| | | voicePlayer.playerInterrupt() |
| | | } |
| | |
| | | |
| | | print("--->开始答题:剩余:\(answerSet.count)") |
| | | |
| | | DispatchQueue.main.asyncAfter(deadline: .now()+3) { |
| | | if listen1Model.data?.playNow == true{ |
| | | self.currentAnswer = self.answerSet.randomElement() //随机 |
| | | if self.timer == nil{self.startTimer()} |
| | | }else{ |
| | | DispatchQueue.main.asyncAfter(deadline: .now()+3) { |
| | | self.currentAnswer = self.answerSet.randomElement() //随机 |
| | | if self.timer == nil{self.startTimer()} |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | override func setUI() { |
| | |
| | | timer = Timer(timeInterval: 1.0, target: self, selector: #selector(runloopTime), userInfo: nil, repeats: true) |
| | | } |
| | | timer?.fire() |
| | | RunLoop.current.add(timer!, forMode: .default) |
| | | RunLoop.current.add(timer!, forMode: .common) |
| | | } |
| | | |
| | | @objc private func runloopTime(){ |
| | |
| | | copyView.frame = CGRect(x: x, y: y, width: layout.itemSize.width - 10, height: 40) |
| | | } completion: { _ in |
| | | DispatchQueue.main.asyncAfter(deadline: .now()+0.5) { |
| | | // self.collectionView.reloadData() |
| | | self.voicePlayer.playerAt(url: self.currentAnswer?.correct) |
| | | self.timer?.fireDate = .distantFuture |
| | | //答题完成 |
| | | // if self.answerSet.count == 0{ |
| | | // self.completeQuestion() |
| | | // } |
| | | } |
| | | } |
| | | } |
| | | |
| | | case .fail: |
| | | rootViewModel.errorNum += 1 |
| | | totalCount += 1 |
| | | label_class.text = "\(totalCount)" |
| | | viewModel.answerType.accept(.fail) |
| | | //移除当前题目 |
| | | if let c = currentAnswer{ |
| | | answerSet.remove(c) |
| | | } |
| | | collectionView.reloadData() |
| | | DispatchQueue.main.asyncAfter(deadline: .now()+3) { |
| | | self.times = self.listen1Model?.data?.time ?? 10 |
| | | self.currentAnswer = self.answerSet.randomElement() |
| | | } |
| | | case .none: |