Reputation: 13051
I made UIScrollView with some UIButton inside. The problem is that when I scroll down at the end of view, it return on start. What can i do? I use this in viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad]; // step 3
scroll.scrollEnabled=YES;
scroll.contentSize = [self.view sizeThatFits:CGSizeZero];
}
Upvotes: 0
Views: 140
Reputation: 1931
According to Apple Documentation: sizeThatFits returns the size portion of the view’s bounds rectangle.
So your scroll view content size is of the same size of the UIView, thats why the scroll view returns to its original position. You need to set the height of the content size to the total height of your entire content in the scroll view. Normally this is bigger, because otherwise it won't make sense to use a UIViewController.
So, use something like this and it should work:
- (void)viewDidLoad
{
[super viewDidLoad]; // step 3
scroll.scrollEnabled=YES;
CGSize scrollViewSize = [self.view sizeThatFits:CGSizeZero];
scrollViewSize.height = 800.0; // Set here the height of the total area of your ScrollView. Should be bigger than the visible area.
scroll.contentSize = scrollViewSize;
}
Upvotes: 1