UIPageControl - Change page on click of button

2019-02-28 07:52发布

I am using UIPageControl along with UISwipeGestureRecognizer to switch between view controllers. The pages are changed using swipe.

I also need to change the page when a UIButton is pressed on one of the view controllers.

Here is how the swipe is used to change the views:

- (void)swipeRightToLeftGesture:(UIGestureRecognizer *)gestureRecognizer {
    if (self.pageControl.currentPage == 0) { 
       [UIView animateWithDuration:1
                 animations:^{

                     for (UIViewController *vc in self.childViewControllers) {
                         CGRect frame = vc.view.frame;
                         frame.origin.x -= self.view.frame.size.height;
                         vc.view.frame = frame;
                 }
      }];
      self.pageControl.currentPage = 1;
   }
}

I hope the question is clear. I tried my best to make it clear.

1条回答
Juvenile、少年°
2楼-- · 2019-02-28 08:08

It's a little cheeky, really you should refactor the method, but:

Assuming you are on page zero (I guess there is a different button on page 1), then you can just call your method and pass nil as the parameter. The gesture isn't actually used so everything should be fine.

查看更多
登录 后发表回答