Last active
October 4, 2016 19:45
-
-
Save thornpig/9d37e6a0dc4f50831e84b11eada63d29 to your computer and use it in GitHub Desktop.
Lock scroll view scroll to horizontal or vertical direction
This file contains hidden or 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
| scrollView.directionalLockEnabled still allows diagonal scrolling. | |
| -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView | |
| { | |
| self.initialOffeset = scrollView.contentOffset; | |
| } | |
| -(void)scrollViewDidScroll:(UIScrollView *)scrollView | |
| { | |
| //lock scroll direction | |
| CGFloat xdis = scrollView.contentOffset.x - self.initialOffeset.x; | |
| CGFloat ydis = scrollView.contentOffset.y - self.initialOffeset.y; | |
| if (fabs(xdis) >= fabs(ydis)) | |
| { | |
| scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x, self.initialOffeset.y); | |
| } | |
| else | |
| { | |
| scrollView.contentOffset = CGPointMake(self.initialOffeset.x, scrollView.contentOffset.y); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment