UIScrollView snap to grid
Implementing snap to grid functionality of UIScrollView:
-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
CGFloat target = targetContentOffset->x;
//calculate new target
CGFloat newTarget = newTargetFromTarget(target);
targetContentOffset->x = newTarget;
}
The targetContentOffset->x/y actually notifies the UIScrollView about the change and it scrolls to the new target instead.
Written by Dominik Krejcik
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Uiscrollview
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#