I need something like this
+ scrollview
|
|__ moving content
|
|__ non moving content
The tricky part is that I'm modifying an existing piece of code where I can't use the
scrollview parent to set the "non moving content" as it's child. The non moving content
must be a scrollview child. I was thinking of attaching it to the background view but
I don't know how to access the UIScrollview's background view.
I believe the "recommended" way to do this is to override layoutSubviews in a custom UIScrollView subclass. This was covered (IIRC) in a 2010 WWDC session you ought to be able to get if you are a developer program member.
Assuming you can't subclass UIScrollView (given your restrictions on modifying existing code), you can do something like the following.
Let "staticView" be the "non moving content" you wish to keep fixed:
UIView *staticView;
Create an ivar (probably in your view controller) to hold its initial center:
CGPoint staticViewDefaultCenter = [staticView center]; // Say, in viewDidLoad
Make your view controller the scroll view's delegate if it isn't already, then implement something like the following:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGPoint contentOffset = [scrollView contentOffset];
CGPoint newCenter = CGPointMake(staticViewDefaultCenter.x + contentOffset.x,
staticViewDefaultCenter.y + contentOffset.y);
[staticView setCenter:newCenter];
}
This will cover the simple case of a scrollable view. Handling a zoomable view gets a little trickier and will depend in part on how you have implemented your viewForZoomingInScrollView: method, but follows an analogous procedure (this time in scrollViewDidZoom: of course).
I haven't thought through the implications of having a transform on your staticView - you may have to do some manipulations in that case too.