Change page on UIScrollView

后端 未结 12 1328
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 18:45

I have a UIScrollView with 10 pages. I am able to flick between them. I also want to have 2 buttons (a back button and a next button) which when touched will go to the previ

12条回答
  •  情歌与酒
    2020-12-04 19:21

    You can do it this way :

    CGRect lastVisibleRect;
    CGSize contentSize = [_scrollView contentSize];
    lastVisibleRect.size.height = contentSize.height; 
    lastVisibleRect.origin.y = 0.0; 
    lastVisibleRect.size.width = PAGE_WIDTH; 
    lastVisibleRect.origin.x  = contentSize.width - PAGE_WIDTH * (_totalItems - pageIndex); // total item of scrollview and your current page index
    
    [_scrollView scrollRectToVisible:lastVisibleRect animated:NO];
    

提交回复
热议问题