nevyn
nevyn

Reputation: 7122

Custom UIControl gets touchesCancelled when scrolling; how do I disable scroll?

I'm writing a UISwitch replacement (with custom graphics). I've overridden touchesMoved and friends, so that you can drag the widget between Yes and No, just as with UISwitch.

If you place it in a scroll view, touches will be cancelled if the user moves her finger the tiniest bit diagonally instead of perfectly horizontally, and scrolling kicks in instead. I've noted that UISwitch and UIButton do not exhibit this behavior, and scrolling never kicks in while manipulating these controls.

How can I tell UIKit that I want exclusive control over these touches, in effect disabling scroll in touchesBegan and enabling scroll in ended/cancelled? I'm sure there's something obvious, but I've looked through the headers and documentation for UIControl, UIResponder, UIView and UIScrollView and haven't found anything.

Note: I don't want to make a UIScrollView subclass; I can't imagine that being the right solution, the control should be completely standalone.

Upvotes: 8

Views: 2849

Answers (1)

jnic
jnic

Reputation: 8785

Setting canCancelContentTouches = NO in the scroll view, and exclusiveTouch = YES in a custom control allows this behaviour, assuming you are happy changing properties on the scroll view.

Upvotes: 4

Related Questions