| | |
| | | return collection |
| | | }() |
| | | |
| | | private var voicePlayer = VoicePlayer.share() |
| | | |
| | | private var isPlayedSet = Set<Int>() |
| | | |
| | | required init(page:Int,listen1Model:Listen1Model){ |
| | | super.init(nibName: nil, bundle: nil) |
| | | self.page = page |
| | | self.listen1Model = listen1Model |
| | | } |
| | | |
| | | |
| | | override func viewDidAppear(_ animated: Bool) { |
| | | super.viewDidAppear(animated) |
| | | voicePlayer.delegate = self |
| | | } |
| | | |
| | | override func viewDidDisappear(_ animated: Bool) { |
| | | super.viewDidDisappear(animated) |
| | | voicePlayer.delegate = nil |
| | | } |
| | | |
| | | required init?(coder: NSCoder) { |
| | |
| | | handleView.vioceSoundUrl = listen1Model.storyList[page].error.components(separatedBy: ",").last |
| | | } |
| | | handleView.btn_choose.tag = 10 + index |
| | | handleView.tag = 20 + index |
| | | handleView.chooseClouse {[weak self] btn in |
| | | guard let weakSelf = self else { return } |
| | | |
| | |
| | | |
| | | switch lessionType { |
| | | case .success: |
| | | weakSelf.viewModel.answerType.accept(.success) |
| | | weakSelf.rootViewModel.correctNum += 1 |
| | | handleView.btn_choose.isSelected = true |
| | | handleView.btn_state.setImage(UIImage(named: "icon_success_small"), for: .normal) |
| | | UIView.animate(withDuration: 0.5) { |
| | | handleView.btn_state.alpha = 1 |
| | | } |
| | | weakSelf.voicePlayer.playerAt(url: handleView.vioceSoundUrl) |
| | | let copyView = handleView.copyView() |
| | | copyView.btn_choose.alpha = 0 |
| | | copyView.listenType = .lesson2 |
| | | copyView.resetView() |
| | | let newRect = handleView.convert(handleView.bounds, to: weakSelf.view) |
| | | weakSelf.view.addSubview(copyView) |
| | | copyView.snp.makeConstraints { make in |
| | | make.top.equalTo(newRect.origin.y) |
| | | make.left.equalTo(newRect.origin.x) |
| | | make.width.equalTo(221) |
| | | make.height.equalTo(52) |
| | | } |
| | | weakSelf.view.layoutIfNeeded() |
| | | |
| | | DispatchQueue.main.asyncAfter(delay: 1.0) { |
| | | var dict = Dictionary<String,Any>() |
| | | dict["storyIntegral"] = weakSelf.listen1Model.data?.lookIntegral ?? 0 |
| | | dict["storyId"] = weakSelf.listen1Model.data?.id ?? 0 |
| | | NotificationCenter.default.post(name: NextLession_Noti, object: dict) |
| | | VoicePlayer.share().playerEnd() |
| | | return |
| | | let rect = weakSelf.collectionView.convert(weakSelf.collectionView.bounds, to: weakSelf.view) |
| | | |
| | | UIView.animate(withDuration: 0.5) { |
| | | copyView.snp.remakeConstraints { make in |
| | | make.top.equalTo(rect.origin.y + 135) |
| | | make.centerX.equalToSuperview().offset(30) |
| | | make.width.equalTo((JQ_ScreenW - 210 * 2)) |
| | | make.height.equalTo(52) |
| | | } |
| | | weakSelf.view.layoutIfNeeded() |
| | | } |
| | | |
| | | case .fail: |
| | | weakSelf.viewModel.answerType.accept(.fail) |
| | | weakSelf.rootViewModel.errorNum += 1 |
| | | handleView.btn_state.setImage(UIImage(named: "icon_waring_small"), for: .normal) |
| | | UIView.animate(withDuration: 0.5) { |
| | | handleView.btn_state.alpha = 1 |
| | | } |
| | | DispatchQueue.main.asyncAfter(deadline:.now()+3) { |
| | | UIView.animate(withDuration: 0.5) { |
| | | handleView.btn_state.alpha = 0 |
| | | handleView.btn_choose.isSelected = false |
| | | } |
| | | } |
| | | |
| | | |
| | | default: |
| | | handleView.btn_state.setImage(nil, for: .normal) |
| | | } |
| | | } |
| | | |
| | | handleView.playAt {[weak self] index in |
| | | self?.isPlayedSet.insert(index) |
| | | print("播放过的\(index)") |
| | | } |
| | | |
| | | handleView.snp.makeConstraints { make in |
| | | make.height.equalTo(52) |
| | | make.width.greaterThanOrEqualTo(159) |
| | | make.width.greaterThanOrEqualTo(221) |
| | | } |
| | | tempHandleViews.append(handleView) |
| | | } |
| | | |
| | | tempHandleViews.shuffle() |
| | | stackView.addArrangedSubviews(tempHandleViews) |
| | | } |
| | | |
| | | func restore(){ |
| | | viewModel.answerType.accept(.none) |
| | | isPlayedSet.removeAll() |
| | | for v in stackView.arrangedSubviews as! [StudyHandleView]{ |
| | | v.resetView() |
| | | v.view_choose.alpha = 0 |
| | | } |
| | | setUI() |
| | | collectionView.reloadData() |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | extension HomeListenStory_1_VC:VoicePlayerDelegate{ |
| | | func playComplete() { |
| | | |
| | | if viewModel.answerType.value == .success{ |
| | | DispatchQueue.main.asyncAfter(delay: 3.0) { |
| | | var dict = Dictionary<String,Any>() |
| | | dict["storyIntegral"] = self.listen1Model.data?.lookIntegral ?? 0 |
| | | dict["storyId"] = self.listen1Model.data?.id ?? 0 |
| | | NotificationCenter.default.post(name: NextLession_Noti, object: dict) |
| | | } |
| | | return |
| | | } |
| | | |
| | | for v in stackView.arrangedSubviews as! [StudyHandleView]{ |
| | | v.resetView() |
| | | v.view_choose.alpha = isPlayedSet.contains(v.tag) ? 1:0 |
| | | } |
| | | } |
| | | |
| | | func playing() { |
| | | |
| | | } |
| | | } |