1

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 Answer 1

1

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.

3
  • 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
    Sep 10, 2010 at 4:00
  • 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. Sep 12, 2010 at 9:55
  • Cheers for that, worked like a charm and a lot cleaner as well.
    – Rudiger
    Sep 16, 2010 at 3:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.