UIPageControl - Change page on click of button

柔情痞子 提交于 2019-12-02 09:36:58

问题


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:


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.



来源:https://stackoverflow.com/questions/21195283/uipagecontrol-change-page-on-click-of-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!