iosarraysxcodepaginationuiscrollview

Creating a button leads to image array


I've followed this tutorial for Paging with UIScrollView and it has some arrays with images. and I want to create a button which takes me to image array that I've chosen (To clarify : When I tap on the button it takes me to photo3.png). Please review the tutorial first in order to understand what I mean. Thanks in advance


Solution

  • Have you tried using the following task of UIScrollView?

    - (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated

    You simply pass a CGRect matching the frame of the page you would like to display.

    EDIT added code

    -(IBAction)scrollToPageNumberFive:(id)sender {
      int scrollToPage = 5; //just an example
      int scrollToX = 5-1; //because X starts from 0
      [self.scrollView scrollRectToVisible:CGRectMake(scrollToX*self.scrollView.frame.size.width,0,self.scrollView.frame.size.width,self.scrollView.frame.size.height) animated:YES];
    }
    

    Calling the scrollRectToVisible:animated: will call the scrollViewDidScroll: method from the tutorial that will load and purge appropriate pages.