Skip to content

Instantly share code, notes, and snippets.

@e23z
Created July 26, 2017 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e23z/a712e95eb1f994131f8a4b793ae768c3 to your computer and use it in GitHub Desktop.
Save e23z/a712e95eb1f994131f8a4b793ae768c3 to your computer and use it in GitHub Desktop.
[Infinite UIScrollView] Example on how to develop an infinite scrolling UIScrollView for mocks. #ios #objectivec #mobile #ui
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
if(scrollView.contentOffset.x == 0) {
CGPoint newOffset = CGPointMake(scrollView.bounds.size.width+scrollView.contentOffset.x, scrollView.contentOffset.y);
[scrollView setContentOffset:newOffset];
[self rotateViewsRight];
}
else if(scrollView.contentOffset.x == scrollView.bounds.size.width*2) {
CGPoint newOffset = CGPointMake(scrollView.contentOffset.x-scrollView.bounds.size.width, scrollView.contentOffset.y);
[scrollView setContentOffset:newOffset];
[self rotateViewsLeft];
}
}
-(void)rotateViewsRight {
UIView *endView = [_contentViews lastObject];
[_contentViews removeLastObject];
[_contentViews insertObject:endView atIndex:0];
[self setContentViewFrames];
}
-(void)rotateViewsLeft {
UIView *endView = _contentViews[0];
[_contentViews removeObjectAtIndex:0];
[_contentViews addObject:endView];
[self setContentViewFrames];
}
-(void) setContentViewFrames {
for(int i = 0; i < 3; i++) {
UIView * view = _contentViews[i];
[view setFrame:CGRectMake(self.view.bounds.size.width*i, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment