UIScrollView 1D Bouncing but 2D Scrolling
-
26-06-2021 - |
Question
The project I'm currently working requires that a UIScrollView
to scroll vertically and horizontally, however, it must only bounce vertically. Is this possible? I noticed that there is a verticalBouncing
and horizontalBouncing
property in the declaration, could that be the answer?
La solution
You cannot access @package
ivars directly. However, you can register yourself as delegate of UIScrollView
and implemenet this code
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
float maxX = scrollView.contentSize.width - scrollView.frame.size.width;
CGPoint offset = scrollView.contentOffset;
offset.x = MAX(MIN(maxX, offset.x), 0);
scrollView.contentOffset = offset;
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow