Created
July 26, 2017 16:03
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(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