UIScroll查看下一个上一个按钮

时间:2012-01-10 10:04:40

标签: iphone objective-c image uiscrollview

我有一个滚动视图。在滚动视图里面,我有图像视图。我想通过按钮点击进入下一个和上一个图像。在下面它只适用于三个不超过数组的图像,以便如何为所有人工作。我在阵列中有70个图像

        - (IBAction)nextButtonAction {

               int arraycount = [appDelegate.articles count];

               NSLog(@" arraycount : %d", arraycount);

               NSLog(@" [pageControl currentPage] : %d", [pageControl currentPage]);

               for (int nextIndex = [pageControl currentPage]; nextIndex < (arraycount-1); nextIndex++) {

               if ( self.scrollView.contentOffset.x <= self.scrollView.frame.size.width ) {

                CGRect frame;
                frame.origin.x = self.scrollView.contentOffset.x +     self.scrollView.frame.size.width;
                frame.origin.y = 0;
                frame.size = self.scrollView.frame.size;
                [self.scrollView scrollRectToVisible:frame animated:YES];
                pageControlBeingUsed = YES;
                }  
            }

        }


-(IBAction)previousButtonAction{

          if ( self.scrollView.contentOffset.x >= self.scrollView.frame.size.width ) {
          CGRect frame;
          frame.origin.x = self.scrollView.contentOffset.x -     self.scrollView.frame.size.width;
          frame.origin.y = 0;
          frame.size = self.scrollView.frame.size;
          [self.scrollView scrollRectToVisible:frame animated:YES];
          pageControlBeingUsed = YES;
          } 

   }

2 个答案:

答案 0 :(得分:0)

    - (IBAction)nextButtonAction {

        int arraycount = [appDelegate.articles count];

        if ( self.scrollView.contentOffset.x < (self.scrollView.frame.size.width *arraycount) ) {

            CGRect frame;
            frame.origin.x = self.scrollView.contentOffset.x +     self.scrollView.frame.size.width;
            frame.origin.y = 0;
            frame.size = self.scrollView.frame.size;
            [self.scrollView scrollRectToVisible:frame animated:YES];
            pageControlBeingUsed = YES;

        }

    }

答案 1 :(得分:0)

- (IBAction)btn_NextPressed:(id)sender
{
    CGFloat pageWidth = self.scrollview.frame.size.width;
    intPage = (NSInteger)floor((self.scrollview.contentOffset.x * 2.0f + pageWidth) / (pageWidth * 2.0f));
   [self.scrollview setContentOffset:CGPointMake(self.scrollview.contentOffset.x + self.scrollview.contentSize.width/numberOfPages ,0) animated:YES];
}

- (IBAction)btn_PrevPressed:(id)sender
{
    CGFloat pageWidth = self.scrollview.frame.size.width;
    intPage = (NSInteger)floor((self.scrollview.contentOffset.x * 2.0f + pageWidth) / (pageWidth * 2.0f));
    [self.scrollview setContentOffset:CGPointMake(self.scrollview.contentOffset.x - self.scrollview.contentSize.width/numberOfPages ,0) animated:YES];
}