When creating the scrollview, make sure you set this:
scrollView.showsHorizontalScrollIndicator = false
scrollView.showsVerticalScrollIndicator = false
scrollView.pagingEnabled = true
Then add your subviews to the scroller at an offset equal to their index * height of the scroller. This is for a vertical scroller:
UIView * sub = [UIView new];
sub.frame = CGRectMake(0, index * h, w, subViewHeight);
[scrollView addSubview:sub];
If you run it now the views are spaced out, and with paging enabled they scroll on one at a time.
So then put this in your viewDidScroll method:
int index = scrollView.contentOffset.y / h;
float y = scrollView.contentOffset.y;
float p = (y / h)-index;
int subViewHeight = h-240;
int spacing = 30;
NSArray * array = scrollView.subviews;
for (UIView * sub in array){
int subIndex = (int)[array indexOfObject:sub];
float transform = (-h * subIndex);
transform += (subViewHeight + spacing) * subIndex;
transform += (h - subViewHeight - spacing) * p;
transform += index * (h - subViewHeight - spacing);
sub.transform = CGAffineTransformMakeTranslation(0, transform);
}
The frames of the subviews are still spaced out, we're just moving them together via a transform as the user scrolls.
Also, you have access to the variable p above, which you can use for other things, like alpha or transforms within the subviews. When p == 1, that page is fully being shown, or rather it tends towards 1.