modalviewcontrollerios13uicontrol

Custom UIControl slider doesn't work when embedded in iOS13 modal viewController


When I embed a custom UIControl inside a ViewController that's presented modally with the new iOS13 automatic style, touchesCancelled is called whenever a pan gesture moves more than a few points.

The native UIKit UISlider doesn't do this. You can pan a UISlider within an automatic style modal ViewController without issue.

UIScrollView has touchesShouldCancel(in view: UIView) where you can force it to allow touches in specified views but I can't find anything in the docs for this new style of modal presentation.


Solution

  • The issue seems to be in using overrides of the UIControl functions touchesBegan, touchesMoved, touchesEnded, and touchesCancelled to observe drags. These touch events can't be intercepted like is possible with UIGestureRecognizerDelegate so there's no way to stop the modal drag from forcing touchesCancelled.

    The answer seems to be: don't use UIControl touch event methods. Rather, - like other answers indicate works - use a UIPanGestureRecognizer and the delegate method gestureRecognizerShouldBegin.

    The trouble all along was trying to use a UIControl as Apple documents say you should.