Reputation: 21870
I'm not really sure why this isn't working, hopefully you can help me find the missing piece. I have a UIScrollView
with paging enabled. I'm using it for side-scrolling through a tutorial. I have a button that when tapped should scroll the user back to the beginning of the tutorial. I originally tried using the scroll view's frame as the rect to scroll to because that CGRect
should represent the first page. I've tried a couple of different CGRects
to no avail though.
- (IBAction) touchedButtonReturnToBeginning:(id)sender {
// I've tried several CGRect's, none of which cause the UIScrollView to move.
// CGRect beginning = self.containerScrollView.frame
// CGRect beginning = self.containerScrollView.bounds;
CGRect beginning = CGRectMake(0, 44, 1, 1);
[self.containerScrollView scrollRectToVisible:beginning animated:YES];
}
I have verified that self.containerScrollView
is hooked up in my xib
as well as the touchedButtonReturnToBeginning
action is connected to my button. I've used my debugger to step through this method, so I have verified that it is getting called. All of the variables are appropriately set, but when I call scrollRectToVisible
the scroll view just doesn't do anything.
Any ideas?
Upvotes: 2
Views: 7478
Reputation: 381
To make scrollRectToVisible works check your self.containerScrollView.contentSize. It should be big enough :)
Upvotes: 5
Reputation: 185671
I don't know why that wouldn't work, but have you tried [self.containerScrollView setContentOffset:CGPointZero animated:YES]
?
Upvotes: 11