Last active
August 29, 2015 14:01
-
-
Save hsjunnesson/c11cb403e0cfc2a8432b to your computer and use it in GitHub Desktop.
Using ReactiveCocoa to get rid of the scroll view delegate, to update a UIPageControl's currentPage as you scroll.
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
CGFloat pageWidth = CGRectGetWidth(self.scrollView.frame); | |
RAC(self.pageControl, currentPage) = [RACObserve(self.scrollView, contentOffset) map:^id(NSValue *value) { | |
CGPoint contentOffset = [value CGPointValue]; | |
NSUInteger page = floor((contentOffset.x - pageWidth / 2) / pageWidth) + 1; | |
return @(page); | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment