Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 986
nevyn Avatar asked Mar 22 '11 10:03

nevyn


1 Answers

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.

like image 94
jnic Avatar answered Sep 20 '22 19:09

jnic