سؤال

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.

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top