You can add a UISwipeGestureRecognizer to your view and in the selection method of the UISwipeGestureRecognizer based on the direction that the UIPageControl object updates, either increase the current page or decrease it.
You can link to the code below. Adding swipe gestures to the view controller
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)]; swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft; [self.view addGestureRecognizer:swipeLeft]; UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)]; swipeRight.direction = UISwipeGestureRecognizerDirectionRight; [self.view addGestureRecognizer:swipeRight];
Scroll gesture selector
- (void)swipe:(UISwipeGestureRecognizer *)swipeRecogniser { if ([swipeRecogniser direction] == UISwipeGestureRecognizerDirectionLeft) { self.pageControl.currentPage -=1; } else if ([swipeRecogniser direction] == UISwipeGestureRecognizerDirectionRight) { self.pageControl.currentPage +=1; } _dssview.image = [UIImage imageNamed: [NSString stringWithFormat:@"%d.jpg",self.pageControl.currentPage]]; }
Add output to UIPageControl in .h file
@interface PageViewController : UIViewController @property (strong, nonatomic) IBOutlet UIImageView *dssview; @property (strong, nonatomic) IBOutlet UIPageControl *pageControl; - (IBAction)changephoto:(UIPageControl *)sender; @end
source share