Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 307
thattyson Avatar asked Jan 25 '23 18:01

thattyson


1 Answers

You can implement gestureRecognizerShouldBegin of UIGestureRecognizerDelegate on your UIControl and return false if it is of UIPanGestureRecognizer

//MARK: UIGestureRecognizerDelegate
extension RangeSlider: UIGestureRecognizerDelegate {
    public override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        return !(gestureRecognizer is UIPanGestureRecognizer)
    }
}
like image 88
Marlo Quidato Avatar answered Apr 29 '23 01:04

Marlo Quidato