Reputation: 279
So, I have a ScrollView which has cards on it. ScrollView must be paging enabled.
The goal is that the user must be able to scroll it, even if it has only one card. Since i am having the frame of ScrollView of exactly the same width and height as a picture of a card, i decided to increase the width of a ScrollView.contentSize and add one point to it.
It turns out to be working fine, but it glitches a bit - when i drag the card to the left, and then grab it again it moves to right a little bit (i guess, for the value of that one point). If i increase the contentSize, the shift increases too (for example, if the content size is increased by ten, the shift value is ten points too). It really irritates me a lot and I want to get rid of it.
Any advice on how to do that? Help is much appreciated.
UPD: I tried to manually re-center the card in the scrollViewDidEndDecelerating but that didn't help. My guess for now is that the problem can be solved by setting the content offset to the right value (because now it's (0,0)), but I can't figure out how to do it.
UPD2: Here is some code that i use for now:
calendarScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 334, 372)];
//The cards themselves are 334 points wide too
calendarScrollView.clipsToBounds = NO;
calendarScrollView.pagingEnabled = YES;
calendarScrollView.bounces = YES;
calendarScrollView.showsHorizontalScrollIndicator = NO;
calendarScrollView.delegate = self;
//This part is used in the cycle of creating the cards
for (...) {
...
if (onlyOneCard) {
calendarScrollView.contentSize = CGSizeMake(335, 372);
onlyOneCard = 0;
} else {
calendarScrollView.contentSize = CGSizeMake(334+offsetInScrollView, 372); //offsetInScrollView is increased by 334 by every end of the iteration of the cycle
}
...
}
Upvotes: 1
Views: 423
Reputation: 5061
You could set the scrollview's bounces property to TRUE.
It will then always bounce back if you've gone beyond the bounds of the scroll view. :)
Upvotes: 2