views:

48

answers:

1

Hi all,

This is more of a check as I believe this is right but its a lot of work if I'm wrong.

I want to basically achieve fixed positioning with a scrollView. I want to have a list along the top that is always visible, scrolls horizontal only and then a scrollview beneath that to move around the information which scrolls both vertically and horizontally.

I figure I need to subclass UIScrollView and overwrite touchesBegan, touchesMoved and touchesEnded to send the touch to both UIScrollViews.

Is this right or off track?

Cheers

+1  A: 

Overriding the touch events on a scroll view is probably not what you want to do. Instead you can simply use a single scroll view, and then in the parent view's -layoutSubviews or in the scroll view's delegate methods you can move the list so it's always at the same vertical position (use the scroll view's contentOffset property to determine where that should be). Both the delegate method and -layoutSubviews is called before the drawing actually occurs after the scroll view scrolls, so by always repositioning your view where you want it to be, it will appear to remain fixed to the user.

Kevin Ballard
Oh ok, so UIView in the UIScrollView that you set the position in layoutSubview or the delegate method? I base this on nothing but will this cause a performance problem constantly moving a view around?
Rudiger
No, this won't cause a performance problem. If you want to see an example of it in action, look at UITableView. It uses this to pin the header for the current section to the top of the screen as you scroll upwards.
Kevin Ballard
Cheers for that, worked like a charm and a lot cleaner as well.
Rudiger