Rectangle 27 0

ios Why setting pagingEnabled to YES in UIScrollView automatically scrolls to previous page when the sub views are touched?


// noOfpages = No of pages in scrollview (Each page has 8 subviews)
// noOfSubviews
int noOfpages = 
if(noOfSubviews%8==0){
   noOfPages = noOfSubviews/8;

}else{
   noOfPages = noOfSubviews/8 + 1;
}
scrollview.contentSize = CGSizeMake(scrollview.frame.size.width*noOfPages,scrollview.frame.size.height);

In this way scrolling on first page will take you to view 9. and scrolling back will take you back to subview 1-8.

The problem is that Paginenabled property of UIScrollView always scroll the scrollview to width of its bounds. So When you have 9 subviews it tries to scroll to 2nd page and shows you 2-9 subviews. In actual your page1 has subviews 1-8 and 2nd pgae has only 9 number subview. So The real problem is that UIScrollview's content width should be proportional to your number of Pages. In your case your 1 page holds 8 subviews. so content size should be Width of UIScrollview * no. of Pages.

Note