Situation: I have a toolbar of sorts (not a UIToolbar, just a custom UIView) that sits at the top of my view. This toolbar has a number of buttons. Immediately below it, I have a scrollview with a form. When a button on the toolbar is tapped, the corresponding form should be animated onto the screen from the right or the left, depending on which button is tapped. I don't want the toolbar to move on this. However, I do want the toolbar to scroll up when the user scrolls up or down on the scroll view. The way I've accomplished it now is in the scrollViewDidScroll delegate method (note I only allow horizontal scrolling if it's from pressing a button on the toolbar):
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if(scrollView.contentOffset.x != 0 && _shouldScrollHorizontally == NO)
{
CGPoint offset = scrollView.contentOffset;
offset.x = 0;
scrollView.contentOffset = offset;
}
CGRect buttonFrame = [_buttons frame];
buttonFrame.origin.y = -scrollView.contentOffset.y + 10;
[_buttons setFrame:buttonFrame];
}
However, I'm concerned that this is inefficient and will cause some latency. I'm wondering if there's a better way to accomplish what I'm trying to achieve.
At the end of the day, I want the toolbar to remain stationary if the scrollview is scrolled horizontally, but to move with the scrollview if the scrollview is scrolled vertically.
Thanks for any suggestions!