开发者

uiscrollview into pages and move between the pages using an up and down button

I need to make my scrollview into pages and move between the pages using an up and 开发者_开发问答down button.

How to achieve moving between pages with a button?


create a changePage method to call - same as you typically would with a pageControl.

I would suggest if you haven't done this before, try implementing with a pageControl and then switch to a button once you have that sorted.

-(IBAction)changePage:(id)sender {

 CGRect frame = scroll.frame;

 frame.origin.x = frame.size.width * pageControl.currentPage;

 frame.origin.y = 0;

 [scroll scrollRectToVisible:frame animated:YES];

 pageControlIsChangingPage = YES;

}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)_scrollView  {

 pageControlIsChangingPage = NO;

CGFloat pageWidth = _scrollView.frame.size.width;

 int page = floor((_scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;

 pageControl.currentPage = page;

}


-(void)scrollViewDidScroll:(UIScrollView *)_scrollView {

    if (pageControlIsChangingPage) {

        return;

    }

    CGFloat pageWidth = _scrollView.frame.size.width;

    int page = floor((_scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;

    pageControl.currentPage = page;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜