From 923402c835c40445cd20292f961f8a0b001df704 Mon Sep 17 00:00:00 2001 From: Luke Aschenbrenner Date: Fri, 28 Apr 2023 11:44:43 -0500 Subject: [PATCH] working on scroll --- SoundboardQuiz/Base.lproj/Main.storyboard | 18 +++++-- SoundboardQuiz/GameOverViewController.swift | 2 +- .../LevelSelectTableViewController.swift | 1 + SoundboardQuiz/MainGameViewController.swift | 41 +++++++++++++-- .../SquareCollectionViewController.swift | 50 +++++++++++++++++-- 5 files changed, 101 insertions(+), 11 deletions(-) diff --git a/SoundboardQuiz/Base.lproj/Main.storyboard b/SoundboardQuiz/Base.lproj/Main.storyboard index d6a5819..8cea161 100644 --- a/SoundboardQuiz/Base.lproj/Main.storyboard +++ b/SoundboardQuiz/Base.lproj/Main.storyboard @@ -40,7 +40,7 @@ - + @@ -283,7 +283,7 @@ - + @@ -332,7 +332,19 @@ - + + + + + diff --git a/SoundboardQuiz/GameOverViewController.swift b/SoundboardQuiz/GameOverViewController.swift index 1e02cb6..f89c4c3 100644 --- a/SoundboardQuiz/GameOverViewController.swift +++ b/SoundboardQuiz/GameOverViewController.swift @@ -45,7 +45,7 @@ class GameOverViewController: UIViewController { //TODO: below newViewController.setCategoryInfo(catName: categoryName!, sounds: sounds!) newViewController.populateSounds() - + //newViewController.shuffle(itemCount: 4) guard var viewControllers = navigationController?.viewControllers else{ diff --git a/SoundboardQuiz/LevelSelectTableViewController.swift b/SoundboardQuiz/LevelSelectTableViewController.swift index f0df0a9..87e99fe 100644 --- a/SoundboardQuiz/LevelSelectTableViewController.swift +++ b/SoundboardQuiz/LevelSelectTableViewController.swift @@ -146,6 +146,7 @@ class LevelSelectTableViewController: UITableViewController { print("populating category info and sounds") destVC.setCategoryInfo(catName: soundCategory.name!, sounds: soundCategory.sounds!) destVC.populateSounds() + // destVC.shuffle(itemCount: 4) } //MARK: - Setting Category Info For The Main Game View Controller diff --git a/SoundboardQuiz/MainGameViewController.swift b/SoundboardQuiz/MainGameViewController.swift index 2234e3b..1197094 100644 --- a/SoundboardQuiz/MainGameViewController.swift +++ b/SoundboardQuiz/MainGameViewController.swift @@ -28,12 +28,16 @@ class MainGameViewController: UIViewController { self.sounds = sounds as? Set } - func shuffle(){ + func shuffle(itemCount: Int){ if let sub = sounds?.shuffled() { - let slice = sub[0.. Void in +// let indexSet = IndexSet(0...(collectionView.numberOfSections - 1)) +// self.collectionView.insertSections(indexSet) +// self.collectionView.forFirstBaselineLayout.layer.speed = 0.5 +// }, completion: { (finished) -> Void in +// self.collectionView.forFirstBaselineLayout.layer.speed = 1.0 +// self.shuffle() +// self.reload() +// self.collectionView.isUserInteractionEnabled = true +// }) + + UIView.animate(withDuration: 5, animations: { + //[weak self] + + if self.collectionView.numberOfItems(inSection: 0) >= 8 { //if the cell exists + print("scrolling now!") + self.collectionView.alwaysBounceVertical = false + self.collectionView.scrollToItem(at: lastItemIndexPath, at: .top, animated: false) + self.collectionView.layoutIfNeeded() + }else{ + print("err: not enough items to scroll") + } + }, completion: {_ in + guard let sounds = ((self.parent as? MainGameViewController)?.subSounds) else { + return + } + self.sounds = sounds + self.reload() + self.collectionView.isUserInteractionEnabled = true + }) + + + + } override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { @@ -113,7 +157,7 @@ class SquareCollectionViewController: UICollectionViewController, UICollectionVi // cell.name = sounds?[currentIndex].name if let sounds, indexPath.row > sounds.count-1{ - cell.name = "Out of Data" + cell.name = "SHOULD NEVER SEE!" }else{ if let name = sounds?[indexPath.row].name{ cell.name = name