Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

396
Views
Toque pageControl para desplazarse a otra vista (toque los puntos)

He configurado PageViewControll con 2 vistas. Puedo moverme entre las vistas y el control de página (puntos) corresponde a la página correcta; sin embargo, al tocar los puntos no se desplaza a la vista correcta todavía.

Encontré algunas respuestas aquí sobre cómo crear la función, pero no pude implementarla correctamente para que funcione. El código para el controlador de página está debajo (sin la función de toque) El código completo es:

 func configurePageControl() { pageControl = UIPageControl(frame: CGRect(x: 0,y: UIScreen.main.bounds.maxY - 50,width: UIScreen.main.bounds.width,height: 50)) self.pageControl.numberOfPages = viewControllerList.count self.pageControl.currentPage = 0 self.pageControl.alpha = 0.5 self.pageControl.tintColor = UIColor.white self.pageControl.pageIndicatorTintColor = UIColor.black self.pageControl.currentPageIndicatorTintColor = UIColor.white self.view.addSubview(pageControl) } @IBAction func pageControltapped(_ sender: Any) { guard let pageControl = sender as? UIPageControl else { return } let selectedPage = pageControl.currentPage self.setViewControllers([viewControllerList[selectedPage]], direction: .forward, animated: true, completion: nil) } }

¡¡Gracias por cualquier ayuda!!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

  1. Debe crear IBAction para pageControl desde el cual puede detectar qué punto se tocó.

  2. Luego, debe usar setViewControllers(_:direction:animated:completion:) para desplazarse por la página mediante programación.

     func setViewControllers(_ viewControllers: [UIViewController]?, direction: UIPageViewController.NavigationDirection, animated: Bool, completion: ((Bool) -> Void)? = nil)

    Aquí está el enlace a la documentación.

Utilice el siguiente código:

 @IBAction func pageControltapped(_ sender: Any) { guard let pageControl = sender as? UIPageControl else { return } let selectedPage = pageControl.currentPage self.setViewControllers([viewControllerList[selectedPage]], direction: .forward, animated: true, completion: nil) }

Agregue destino para pageControl para vincularlo con IBAction:

 func configurePageControl() { //...your code as it is.... //add following line self.pageControl.addTarget(self, action: #selector(pageControltapped(_:)), for: .touchUpInside) }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!