Reputation: 335
I am trying to simulate what Apple Inc. uses in their "Messages" app, where they have a scroll view that re-adjusts itself to a proper offset if you've gone higher than the top of the scroll view content.
My scrollview takes up the entire screen, but I have a title bar which is in front of the content (like "Messages"). Upon touching the scroll view, the offset is immediately thrown away like garbage and the top content is hidden under the title bar.
My code is currently:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.scroller setDelegate:self];
[self.scroller setScrollEnabled:YES];
[self.scroller setContentSize:CGSizeMake(320, 600)];
//****this offset is for the title bar****
[self.scroller setContentOffset:CGPointMake(0, -100) animated:YES];
// Do any additional setup after loading the view.
}
and I have a function attempting to readjust the view based on y location:
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
if (scrollView.contentOffset.y < 10){
NSLog(@"%@",NSStringFromCGPoint(scrollView.contentOffset));
[scrollView setContentOffset:CGPointMake(0, -100) animated:YES];
}
}
THIS FUNCTION TAKES A LONGGGG TIME before it re-adjusts the view.
So finally, my questions:
How do I make sure that on touch, the scrollview doesn't disregard the content offset, and then slowly adjust itself back to proper offset shortly after.
How do I change the speed at which the content offset is re-adjusted so it is similar to "Messages"?
Upvotes: 4
Views: 10337
Reputation: 335
I found the error to be the fact that I was using:
[self.scroller setContentOffset:CGPointMake(0, -100) animated:YES];
When I should have been using:
[self.scroller setContentInset:UIEdgeInsetsMake(self.statusbar.height,0,0,0)];
Upvotes: 4