How can i change the page on clicking the dots of UIPageControl

前端 未结 4 1479
太阳男子
太阳男子 2020-12-29 18:29

Here I have a pagecontrol which works good but on clicking on dot it doesn\'t change the page so please help in the function of changepage:

- (void)viewDidLo         


        
4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-29 18:54

    Just to complete Banker Mittal's answer, the easiest way to do it in swift is to scroll the wanted rect to visible. You don't have to take care of "left" and "right" scrolling because iOS itself realizes which dot you tapped so you can just scroll to the correct frame:

    private func moveScrollViewToCurrentPage() {
    
     //You can use your UICollectionView variable too instead of my scrollview variable
                self.scrollView
                    .scrollRectToVisible(CGRect(
                        x: Int(self.scrollView.frame.size.width) * self.pager.currentPage,
                        y: 0,
                         width:Int(self.scrollView.frame.size.width),
                        height: Int(self.scrollView.frame.size.height)),
                                         animated: true)
    
        }
    

提交回复
热议问题