I am using a UIScrollView for showing UIButtons horizontally scrolled. Now when I select and highlight a button i shouldn't be able to scroll that button out of view. At time I am allowing only one button to be selected.
After considering the question: How to stop a UIScrollView at a specific point? and implemented the following:
-(void) scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
if(targetContentOffset->x==0){
return;
}else if(targetContentOffset->x>self.maxScrollPoint.x){
targetContentOffset->x=self.maxScrollPoint.x;
}else if (targetContentOffset->x<self.maxScrollPoint.x+self.componentView.frame.size.width){
targetContentOffset->x=self.maxScrollPoint.x+self.componentView.frame.size.width;
}
}
Where maxScrollPoint is the origin of the UIButton in the Scrollview. This implementation is allowing the user to scroll beyond the visible rect and then scrolling back to the origin of the button.
Is there anyway I can restrict the scrollview to stop scrolling beyond that point and also beyond the scrollview's max visible width(not contentsize)