Post

Replies

Boosts

Views

Activity

Swift file not attaching itself to TabBar
Hi so I have a problem with my TabBar and that is that the TabBar isn't connected to my assigned swift file, I've connected the collection view cell to the tab1 (name of the class) but it's not working? What have I missed? I'll send a link to the whole code itself for a better understanding. https://github.com/Gharfield/Tabbar.git Thanks for any help!
0
0
829
Apr ’23
Image slider issues.
Hi so I have a complication with my code and how to get through this, I want to make my automatic image slider being able to be intractable with a swipe from the 3:rd to the first image. I want to be able to do a slide loop, once I slide from the 3:rd picture it will slide to the first image again, making it going in a loop, how is this possible, I've been trying to look around for any solutions but without any success, however it would be much appreciated I someone could take a look at this and give me some feedback. I also have a problem where the automatic image slider still counts down and swipes whilst the user interacts with the slider making it unsmooth. //  ViewController.swift //  StagINC // //  Created by - on 2022-01-08. // import UIKit class ViewController: UIViewController {          //MARK: - Outlets          @IBOutlet var imageCollectionView: UICollectionView!     @IBOutlet var imagePageControl: UIPageControl!          //MARK: - Properties          let sliderImages = [UIImage(named: "3"), UIImage(named: "4"), UIImage(named: "5"), UIImage(named: "2")]          var timer = Timer()     var counter = 0          let layout = UICollectionViewFlowLayout()          //MARK: - View Life Cycle          override func viewDidLoad() {         super.viewDidLoad()                  setupCollectionView()         setupPageControl()         startTimer()     }          //MARK: - Setup Functions          private func setupCollectionView() {                  imageCollectionView.delegate = self         imageCollectionView.dataSource = self         imageCollectionView.showsHorizontalScrollIndicator = false                  layout.scrollDirection = .horizontal         imageCollectionView.collectionViewLayout = layout         imageCollectionView.isPagingEnabled = true         imageCollectionView.isScrollEnabled = true     }          private func setupPageControl() {                  imagePageControl.numberOfPages = sliderImages.count         imagePageControl.currentPage = 0     }          //MARK: - Helper Functions          func startTimer() {                  DispatchQueue.main.async {             self.timer = Timer.scheduledTimer(timeInterval: 3.0, target: self, selector: #selector(self.changeImage), userInfo: nil, repeats: true)         }     }          //MARK: - @objc Functions          @objc func changeImage() {                  if counter < sliderImages.count {             let index = IndexPath.init(item: counter, section: 0)             self.imageCollectionView.scrollToItem(at: index, at: .centeredHorizontally, animated: true)             imagePageControl.currentPage = counter             counter += 1         } else {             counter = 0             let index = IndexPath.init(item: counter, section: 0)             self.imageCollectionView.scrollToItem(at: index, at: .centeredHorizontally, animated: true)             imagePageControl.currentPage = counter             counter += 1         }     } } //MARK: - UICollectionViewDataSource + UICollectionViewDelegate extension ViewController : UICollectionViewDataSource , UICollectionViewDelegate {          func numberOfSections(in collectionView: UICollectionView) -> Int {         return 1     }          func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {         return sliderImages.count     }          func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {                  guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as? MyCollectionViewCell else { return UICollectionViewCell() }                  cell.sliderImageView.image = sliderImages[indexPath.row]                  return cell     } } extension ViewController: UIScrollViewDelegate {          func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {         let pageNumber = round(scrollView.contentOffset.x / scrollView.frame.size.width)         imagePageControl.currentPage = Int(pageNumber)         counter = Int(pageNumber)     }          func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {                  print("User touched the slider!")         timer.invalidate()     }          func scrollViewWillEndDragging(_ _scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {                  print("will end now!")         startTimer()     } } //MARK: - UICollectionViewDelegateFlowLayout extension ViewController: UICollectionViewDelegateFlowLayout {          func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {         let size = collectionView.frame.size         return CGSize(width: size.width, height: size.height)     }          func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {         return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)     }          func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {         return 0.0     }          func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {         return 0.0     } } I also have the full code available at GitHub for easier access. https://github.com/Gharfield/Automatic-Image-Slider-SwiftUI.git
0
1
872
Oct ’22
Thread 1 ERROR MESSAGE
Hi! So im coding and I’m about to lauch the app via the simulator but I’t crashes and I get this error message. Thread 1: “-[UIViewController collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance 0x130f0a530” And I've located the bug but I don’t understand it. The bug happens when I connect the collection view from the mainstory.board to the view controller. Specifically when I add the dataSource from the collection view to the view controller, how can I fix this, cause without this I just get a blanc screen on the sim? I'd happily share the project if that helps solving the issue!
2
0
1.2k
Jan ’22
UIIMAGEVIEW - What's wrong.
Hi im creating an automatic UIIMAGEVIEW in SwiftUI but I can't seem to find the issue, anyone who has any idea? //  ViewController.swift //  StagINC // //  Created by - on 2022-01-08. // import UIKit class ViewController: UIViewController {               @IBOutlet var collectioView: UICollectionView!     @IBOutlet var myPage: UIPageControl!          var SliderImages = [UIImage(named: "3"),UIImage(named: "4"),UIImage(named: "5"),UIImage(named: "2")] //    var SliderImages = [ "3", "4", "5"]      // var SliderImages = [UIImage(named: "2")!, UIImage(named: "2")!, UIImage(named: "2")!]       var timer = Timer()       var counter = 0          override func viewDidLoad() {         super.viewDidLoad()         collectioView.delegate = self         collectioView.dataSource = self           myPage.numberOfPages=SliderImages.count         myPage.currentPage=0         DispatchQueue.main.async {             self.timer = Timer.scheduledTimer(timeInterval: 2.0, target: self, selector: #selector(self.changeImage), userInfo: nil, repeats: true)         }              }          @objc func changeImage(){                  if counter < SliderImages.count {             let index = IndexPath.init(item: counter, section: 0)             self.collectioView.scrollToItem(at: index, at: .centeredHorizontally, animated: true)             myPage.currentPage = counter             counter += 1         }else {             counter = 0             let index = IndexPath.init(item: counter, section: 0)             self.collectioView.scrollToItem(at: index, at: .centeredHorizontally, animated: true)             myPage.currentPage = counter             counter = 1         }              }          // func startTimer(){ timer = Timer.scheduledTimer(timeInterval: 2.5, target: self, selector: #selector(moveToNextIndex), userinfo: nil, repeats: true)       }  // @objc func moveToNextIndex(){ if currentCellIndex < SliderImages.count -1{ currentCellIndex += 1 // } else { currentCellIndex = 0 // } currentCellIndex += 1 collectionView.scrollToItem(at: IndexPath(item: curentCellIndex, section: 0), at: .centeredHorizontally, animated: true)  // pageControl.currentPage = currentCellIndex extension ViewController : UICollectionViewDataSource , UICollectionViewDelegate {     func numberOfSections(in collectionView: UICollectionView) -> Int {         return 1     }     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int{         return SliderImages.count     }     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {         let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! MyCollectionCell                if let vc  = cell.viewWithTag(111) as? UIImageView {             vc.image = SliderImages[indexPath.row] //          cell.myWebImage.image=UIImage(named: SliderImages[indexPath.row])         } else if let ab = cell.viewWithTag(222) as? UIPageControl {             ab.currentPage = indexPath.row         }                  return cell     }          func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {         myPage.currentPage=indexPath.row                   // func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSIZE { return CGSize(width: collectionView.frame.width, height: collectionView.frame.height.       }           // func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { return 0 } extension ViewController :UICollectionViewDelegateFlowLayout {     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {         let size = collectionView.frame.size         return CGSize(width: size.width, height: size.height)     }          func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {         return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)     }          func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {         return 0.0     }          func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {         return 0.0     } }```
1
0
494
Jan ’22
SWIFTUI Image Slideshow using TabView not working
Hi! The code for the Image Slideshow/Image Gallery is not working. Here's the code. I'll have the questions below. Import SwiftUI struct Tab1: View {     private var numberOfImages = 3     private let timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect()     @State private var currentIndex = 0     var body: some View {         GeometryReader { proxy in             TabView(selection:$currentIndex) {             ForEach(0..<numberOfImages) { num in                 Image("\(num)")                     .resizable()                     .scaledToFit() .tag("num")             }           } .tabViewStyle(PageTabViewStyle(indexDisplayMode: .always)) .frame(width: proxy.size.width, height: proxy.size.height / 3).edgesIgnoringSafeArea(.top)             .onReceive(timer, perform: { _ in                 withAnimation {                 currentIndex = currentIndex < numberOfImages ? currentIndex + 1 : 0                 }             })         }         }     } struct Tab1_Previews: PreviewProvider {     static var previews: some View {         Tab1()     } } As you can see it's not much but I still get a lot of problems with it. The slider in the simulation doesn't ignore the safe area as it says, however in the live preview the slider is ignoring the safe area. I am able to drag the image up and down?? and not only vertically like I want The slider is on a timer and switch every 10 seconds, now this brings some issues. 3.1 The timer doesn't reset after manually interacting with it (through scrolling) 3.2 Once the slider is on the last image it resets itself going back to image one, but I can't do this manually. What have I done wrong and how can it be fixed? Thanks for every kind of help, much appreciated. I´ve been stuck on this for months trying to figure it out myself.
1
0
2.0k
Nov ’21
Swift file not attaching itself to TabBar
Hi so I have a problem with my TabBar and that is that the TabBar isn't connected to my assigned swift file, I've connected the collection view cell to the tab1 (name of the class) but it's not working? What have I missed? I'll send a link to the whole code itself for a better understanding. https://github.com/Gharfield/Tabbar.git Thanks for any help!
Replies
0
Boosts
0
Views
829
Activity
Apr ’23
Image slider issues.
Hi so I have a complication with my code and how to get through this, I want to make my automatic image slider being able to be intractable with a swipe from the 3:rd to the first image. I want to be able to do a slide loop, once I slide from the 3:rd picture it will slide to the first image again, making it going in a loop, how is this possible, I've been trying to look around for any solutions but without any success, however it would be much appreciated I someone could take a look at this and give me some feedback. I also have a problem where the automatic image slider still counts down and swipes whilst the user interacts with the slider making it unsmooth. //  ViewController.swift //  StagINC // //  Created by - on 2022-01-08. // import UIKit class ViewController: UIViewController {          //MARK: - Outlets          @IBOutlet var imageCollectionView: UICollectionView!     @IBOutlet var imagePageControl: UIPageControl!          //MARK: - Properties          let sliderImages = [UIImage(named: "3"), UIImage(named: "4"), UIImage(named: "5"), UIImage(named: "2")]          var timer = Timer()     var counter = 0          let layout = UICollectionViewFlowLayout()          //MARK: - View Life Cycle          override func viewDidLoad() {         super.viewDidLoad()                  setupCollectionView()         setupPageControl()         startTimer()     }          //MARK: - Setup Functions          private func setupCollectionView() {                  imageCollectionView.delegate = self         imageCollectionView.dataSource = self         imageCollectionView.showsHorizontalScrollIndicator = false                  layout.scrollDirection = .horizontal         imageCollectionView.collectionViewLayout = layout         imageCollectionView.isPagingEnabled = true         imageCollectionView.isScrollEnabled = true     }          private func setupPageControl() {                  imagePageControl.numberOfPages = sliderImages.count         imagePageControl.currentPage = 0     }          //MARK: - Helper Functions          func startTimer() {                  DispatchQueue.main.async {             self.timer = Timer.scheduledTimer(timeInterval: 3.0, target: self, selector: #selector(self.changeImage), userInfo: nil, repeats: true)         }     }          //MARK: - @objc Functions          @objc func changeImage() {                  if counter < sliderImages.count {             let index = IndexPath.init(item: counter, section: 0)             self.imageCollectionView.scrollToItem(at: index, at: .centeredHorizontally, animated: true)             imagePageControl.currentPage = counter             counter += 1         } else {             counter = 0             let index = IndexPath.init(item: counter, section: 0)             self.imageCollectionView.scrollToItem(at: index, at: .centeredHorizontally, animated: true)             imagePageControl.currentPage = counter             counter += 1         }     } } //MARK: - UICollectionViewDataSource + UICollectionViewDelegate extension ViewController : UICollectionViewDataSource , UICollectionViewDelegate {          func numberOfSections(in collectionView: UICollectionView) -> Int {         return 1     }          func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {         return sliderImages.count     }          func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {                  guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as? MyCollectionViewCell else { return UICollectionViewCell() }                  cell.sliderImageView.image = sliderImages[indexPath.row]                  return cell     } } extension ViewController: UIScrollViewDelegate {          func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {         let pageNumber = round(scrollView.contentOffset.x / scrollView.frame.size.width)         imagePageControl.currentPage = Int(pageNumber)         counter = Int(pageNumber)     }          func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {                  print("User touched the slider!")         timer.invalidate()     }          func scrollViewWillEndDragging(_ _scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {                  print("will end now!")         startTimer()     } } //MARK: - UICollectionViewDelegateFlowLayout extension ViewController: UICollectionViewDelegateFlowLayout {          func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {         let size = collectionView.frame.size         return CGSize(width: size.width, height: size.height)     }          func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {         return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)     }          func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {         return 0.0     }          func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {         return 0.0     } } I also have the full code available at GitHub for easier access. https://github.com/Gharfield/Automatic-Image-Slider-SwiftUI.git
Replies
0
Boosts
1
Views
872
Activity
Oct ’22
Thread 1 ERROR MESSAGE
Hi! So im coding and I’m about to lauch the app via the simulator but I’t crashes and I get this error message. Thread 1: “-[UIViewController collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance 0x130f0a530” And I've located the bug but I don’t understand it. The bug happens when I connect the collection view from the mainstory.board to the view controller. Specifically when I add the dataSource from the collection view to the view controller, how can I fix this, cause without this I just get a blanc screen on the sim? I'd happily share the project if that helps solving the issue!
Replies
2
Boosts
0
Views
1.2k
Activity
Jan ’22
UIIMAGEVIEW - What's wrong.
Hi im creating an automatic UIIMAGEVIEW in SwiftUI but I can't seem to find the issue, anyone who has any idea? //  ViewController.swift //  StagINC // //  Created by - on 2022-01-08. // import UIKit class ViewController: UIViewController {               @IBOutlet var collectioView: UICollectionView!     @IBOutlet var myPage: UIPageControl!          var SliderImages = [UIImage(named: "3"),UIImage(named: "4"),UIImage(named: "5"),UIImage(named: "2")] //    var SliderImages = [ "3", "4", "5"]      // var SliderImages = [UIImage(named: "2")!, UIImage(named: "2")!, UIImage(named: "2")!]       var timer = Timer()       var counter = 0          override func viewDidLoad() {         super.viewDidLoad()         collectioView.delegate = self         collectioView.dataSource = self           myPage.numberOfPages=SliderImages.count         myPage.currentPage=0         DispatchQueue.main.async {             self.timer = Timer.scheduledTimer(timeInterval: 2.0, target: self, selector: #selector(self.changeImage), userInfo: nil, repeats: true)         }              }          @objc func changeImage(){                  if counter < SliderImages.count {             let index = IndexPath.init(item: counter, section: 0)             self.collectioView.scrollToItem(at: index, at: .centeredHorizontally, animated: true)             myPage.currentPage = counter             counter += 1         }else {             counter = 0             let index = IndexPath.init(item: counter, section: 0)             self.collectioView.scrollToItem(at: index, at: .centeredHorizontally, animated: true)             myPage.currentPage = counter             counter = 1         }              }          // func startTimer(){ timer = Timer.scheduledTimer(timeInterval: 2.5, target: self, selector: #selector(moveToNextIndex), userinfo: nil, repeats: true)       }  // @objc func moveToNextIndex(){ if currentCellIndex < SliderImages.count -1{ currentCellIndex += 1 // } else { currentCellIndex = 0 // } currentCellIndex += 1 collectionView.scrollToItem(at: IndexPath(item: curentCellIndex, section: 0), at: .centeredHorizontally, animated: true)  // pageControl.currentPage = currentCellIndex extension ViewController : UICollectionViewDataSource , UICollectionViewDelegate {     func numberOfSections(in collectionView: UICollectionView) -> Int {         return 1     }     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int{         return SliderImages.count     }     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {         let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! MyCollectionCell                if let vc  = cell.viewWithTag(111) as? UIImageView {             vc.image = SliderImages[indexPath.row] //          cell.myWebImage.image=UIImage(named: SliderImages[indexPath.row])         } else if let ab = cell.viewWithTag(222) as? UIPageControl {             ab.currentPage = indexPath.row         }                  return cell     }          func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {         myPage.currentPage=indexPath.row                   // func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSIZE { return CGSize(width: collectionView.frame.width, height: collectionView.frame.height.       }           // func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { return 0 } extension ViewController :UICollectionViewDelegateFlowLayout {     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {         let size = collectionView.frame.size         return CGSize(width: size.width, height: size.height)     }          func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {         return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)     }          func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {         return 0.0     }          func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {         return 0.0     } }```
Replies
1
Boosts
0
Views
494
Activity
Jan ’22
What’s the name of the function.
Hi i want to implement this into my app. Though i don’t know the name of the function im after, so i don’t really know how to build my code. https://drive.google.com/file/d/1h-hWLMRhy69vmdHZLnUjegFFomgodTki/view?usp=drivesdk thanks!
Replies
3
Boosts
0
Views
471
Activity
Nov ’21
SWIFTUI Image Slideshow using TabView not working
Hi! The code for the Image Slideshow/Image Gallery is not working. Here's the code. I'll have the questions below. Import SwiftUI struct Tab1: View {     private var numberOfImages = 3     private let timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect()     @State private var currentIndex = 0     var body: some View {         GeometryReader { proxy in             TabView(selection:$currentIndex) {             ForEach(0..<numberOfImages) { num in                 Image("\(num)")                     .resizable()                     .scaledToFit() .tag("num")             }           } .tabViewStyle(PageTabViewStyle(indexDisplayMode: .always)) .frame(width: proxy.size.width, height: proxy.size.height / 3).edgesIgnoringSafeArea(.top)             .onReceive(timer, perform: { _ in                 withAnimation {                 currentIndex = currentIndex < numberOfImages ? currentIndex + 1 : 0                 }             })         }         }     } struct Tab1_Previews: PreviewProvider {     static var previews: some View {         Tab1()     } } As you can see it's not much but I still get a lot of problems with it. The slider in the simulation doesn't ignore the safe area as it says, however in the live preview the slider is ignoring the safe area. I am able to drag the image up and down?? and not only vertically like I want The slider is on a timer and switch every 10 seconds, now this brings some issues. 3.1 The timer doesn't reset after manually interacting with it (through scrolling) 3.2 Once the slider is on the last image it resets itself going back to image one, but I can't do this manually. What have I done wrong and how can it be fixed? Thanks for every kind of help, much appreciated. I´ve been stuck on this for months trying to figure it out myself.
Replies
1
Boosts
0
Views
2.0k
Activity
Nov ’21