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
804
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
839
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.1k
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
471
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
Image slider not ignoring .edgesignoringSafeArea(.all)
My image slider do not want to ignore the safe area on the top, why is that? 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 {         ZStack {         GeometryReader { proxy in             TabView(selection:$currentIndex) {             ForEach(0..<numberOfImages) { num in                 Image("\(num)")                     .resizable()                     .scaledToFill()                     .tag(num)                 // overlay(Color.black.opacity(0)) if relevant             }             }             .tabViewStyle(PageTabViewStyle())             .clipShape(RoundedRectangle(cornerRadius: 10))             .frame(width: proxy.size.width, height: proxy.size.height / 3)             .onReceive(timer, perform: { _ in                 withAnimation {                 currentIndex = currentIndex < numberOfImages ? currentIndex + 1 : 0                 }             })         }         .edgesIgnoringSafeArea(.all)         }       }     } struct Tab1_Previews: PreviewProvider {     static var previews: some View {         Tab1()     } }```
1
0
507
Jul ’21
The code shows one thing and the preview another
Hi! So the code says that my image is ignoring the safe area, and so does the preview show. BUT the simulator does not show that the safe area is covered. The code is always right? Right..? 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)")                     .tag("num")                 // overlay(Color.black.opacity(0)) if relevant             }             }.tabViewStyle(PageTabViewStyle())             .frame(width: proxy.size.width, height: proxy.size.height / 3).ignoresSafeArea(.all, edges: .top)             .onReceive(timer, perform: { _ in                 withAnimation {                 currentIndex = currentIndex < numberOfImages ? currentIndex + 1 : 0                 }             })         }         }     } struct Tab1_Previews: PreviewProvider {     static var previews: some View {         Tab1()     }   }```
0
0
590
Jun ’21
Image Slider not ignoringsafearea
Hi so my image slider does not ignore my safearea(.top), and i can’t seem to get it fixed no matter what i do. Any suggestions? And also, my slider does not let me manually slide from picture three to the first (to start the cycle over again) and same when im on the first picture it won’t let me go to the third if i swipe left. 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()       .scaledToFill()        .overlay(Color.black.opacity(0.4))       .tag(num)  } }.tabViewStyle(PageTabViewStyle())       .clipShape(RoundedRectangle(cornerRadius: 10)) .frame(width: proxy.size.width, height: proxy.size.height/ 3)          .onReceive(timer, perform: { _ in                 withAnimation {                 currentIndex = currentIndex < numberOfImages ? currentIndex + 1 : 0                 }             })         }      } } struct Tab1_Previews: PreviewProvider {     static var previews: some View {         Tab1()     } }
1
0
931
Jun ’21
Image slider
Hi! https://www.dropbox.com/s/40w8l22bjnul15g/SLIDER.MOV?dl=0 Soo i have a few problems… First: i want the slider to ignore the safe area on top, .edgesignorningsafearea(.top) doesn’t work since there is a frame to it. How can i make it go over the safe area? Second: How can i customize my slider icons. I want them to be lines instead of dots and to be located to the left instead in the middle. Third: As you can see in the video i also can’t drag the picture from the 3rd picture to the first to start the cycle over again. I can’t even drag from 1st back to 3rd. How can i manage this? Fourth: I also want the ImageSlider to stop the timer once the user holds a picture (so if i hold picture one it will stay there and not go to picture two, and makes it unstable) Thanks for the help.
1
0
1.5k
Jun ’21
Recipes App | SwiftUI | Creating the pages
Hi! I’ve got a problem. I’ve currently started with coding of apps and after a few hours and days i finally have a working tabBar with options, icons and different pages the problem is, each of these tabs don’t display anything, when i click them except a white page(since there’s no code for it) How do i make it possible for me to code content into these blank pages that’s gonna show recipes etc. (! The tabBar itself is already completely done) all i want now is to start coding so the tabicons lead me somewhere to like recipes, now i’m coming to a white page. i also want each category to have a seperate file in the coding, like “recipes” have it’s coding in one file and “my account” has a completely seperate file in the coding (so if i accendently erase the “my account” coding the “recipes” coding isn’t affected at all cause it’s not in the same file. // Thanks
5
0
1.5k
Jun ’21
SwiftUI. Want to code in each page that’s connected to the tabBar
Hi! So... I’ve currently been working on an app, well an recipes app. I’ve currently created a TabBarView.swift where the code for the TabBar itself is an alone code, that’s what i think. Anyway, i wanna know how i can create separate SwiftUI (Files or View) for each page itself. Like for example when i press the home button on the TabBar i want to be able to create the content that’s gonna be in home, in a different file, so i easily can organize things, by category of the app, is that possible? Im happy to share the code so you can understand it better on how to fix my problem.
2
0
900
Jun ’21