Uipagecontrol最后一次移动

时间:2016-04-15 06:27:34

标签: ios objective-c iphone uiscrollview uipageviewcontroller

创建Scrollview添加UIPagecontrol并成功加载数组值。放置计时器以自动滚动它。想要在完成最后一个数组值后显示它想要自动移动第一个数组值。(现在我的代码工作就像反转并移动到第一个数组值)。我需要先自动前进。帮我。

Scrollview页面移动代码

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
        int width;
        width = ScrollViewPage.frame.size.width;
        float xPos = scrollView.contentOffset.x+10;
        pageControl.currentPage = (int)xPos/width;
}

///添加使用tis代码自动移动的计时器

- (void)loadNextController
{
     pageControl.currentPage = (pageControl.currentPage+1)%self->pageControllMutableImageArray.count;
    [ScrollViewPage setContentOffset:CGPointMake(pageControl.currentPage * self.view.bounds.size.width, 0) animated:YES];
}

/// UIpagecontrol点按钮点击目标操作代码

- (IBAction)pageTurn:(id)sender
{
    NSUInteger page = pageControl.currentPage;
    CGRect frame = ScrollViewPage.frame;
    frame.origin.x = frame.size.width * page;
    frame.origin.y = 0;
    [ScrollViewPage scrollRectToVisible:frame animated:YES];

}

我的代码怎么可能。帮助我,谢谢你。

1 个答案:

答案 0 :(得分:0)

你可以这样做,

- (void)loadNextController
{
 //put if statement here to check whether it is page object something like,

 //have aasume that your first page number is 0. so take count - 1 in if

  if(pageControl.currentPage == (pageControllMutableImageArray.count - 1)){
   //start from initial. set current page = 0 and contentoffset of first page

  }
  else {

   // your code for next page may be like,

     pageControl.currentPage = (pageControl.currentPage+1)%self->pageControllMutableImageArray.count;
[ScrollViewPage setContentOffset:CGPointMake(pageControl.currentPage * self.view.bounds.size.width, 0) animated:YES];
  }

}

希望这会有所帮助。 :)

更新2:

您可以设置第一页的内容偏移量,如:

   CGPoint newOffset = CGPointMake(0, 0);
    [self.standardScrollView setContentOffset:newOffset animated:YES];