2

Possible Duplicate:
UISlider and UIScrollView

using iOS SDK 4.3. I've found when I have a UISlider as a subview of a UIScrollView when I try to drag the slider it ends up scrolling, this is of course scrolling horizontally.

This is going to be a bad user experience. Anyone know how to implement this to avoid this problem.

Thanks

Community
  • 1
  • 1
tech74
  • 231
  • 2
  • 10

1 Answers1

1

You could watch for touch events in the UISlider, and on the touch down event, you could set scrollEnabled to NO for the UIScrollView, then on the touch up inside & outside events, set it to YES again. See if that solves the issue for you, or does the scrolling of the UIScrollView happen before the UISlider receives any touch events?

EDIT: As Noah pointed out, this won't work. What you can do instead is subclass the UIScrollView and override the touchesBegan, touchesMoved, and touchesEnded methods. Inside there you can check if the touch corresponds to the area that includes the UISlider and pass the touch manually to the slider if it does. I did exactly this for a project I was working on that had a dial (custom control I made) inside a scroll view. I needed to be able to turn the dial without scrolling. When I would detect that a touch landed inside the dial inside touchesBegan I would disable scrolling on the scroll view, then in touchesMoved I would pass them to the dial. Also you may want to look at the hitTest:withEvent: method to intercept some touches there.

Ben Baron
  • 14,496
  • 12
  • 55
  • 65
  • 1
    The way scroll views handle touch forwarding to their subviews means that the slider won’t even get the touch-down event until after the scroll view has discarded it. This won’t work. – Noah Witherspoon Jul 11 '11 at 23:03