Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIControl touches not behaving correctly on left side of VC

Tags:

ios

uitouch

I have a UIControl (subclass of UIView), and when I create it and align it to the left side in my view controller, the "beginTrackingWithTouch" fails to get called when I touch the view. It will only get called when I release the touch. What is weird is that pointInside(point: CGPoint...) method gets called immediately when I touch the UIControl, and what is even weirder is that when I align this UIControl view on the right side of the view controller, it works fine--beginTrackingWithTouch is called immediately when the view is touched, not when released. In addition, beginTrackingWithTouch is called the same time endTrackingWithTouch is called. Through some testing, it works fine until the view is 20 px from the left side, then this strange issue occurs again.

Is there a reason why the UIControl continueTrackingWithTouch fails to register if it is put on the far left side of a view controller? Is this Apple's way of preventing left hand scroll? There is absolutely nothing on the left side which is blocking the UIControl.

//In public class CustomScrollBar : UIControl

//This method gets called everytime when UIControl (red area in picture) is touched
override public func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool {
    return CGRectContainsPoint(handleHitArea, point)
}

//Only gets called when UIControl is touched and let go.  It will not get called until your finger lifts off the screen.
override public func beginTrackingWithTouch(touch: UITouch, withEvent event: UIEvent?) -> Bool {

    self.scrollerLine.hidden = true

    if let delegate = self.delegate {
        delegate.beginTrackingWithTouch()
    }

    guard self.isHandleVisible else{
        return false
    }

    self.lastTouchLocation = touch.locationInView(self)
    self.isHandleDragged = true

    self.setNeedsLayout()

    return true
}

//Image below: UIControl view is on the left side (light blue). If I move this on the far right side, the methods register fine.

enter image description here

like image 356
Josh O'Connor Avatar asked Oct 30 '22 23:10

Josh O'Connor


1 Answers

Navigation controller has a built in back gesture recognizer, set it to false. Make sure that it is set in viewDidAppear

self.navigationController!.interactivePopGestureRecognizer!.enabled = false
like image 93
cup_of Avatar answered Nov 15 '22 06:11

cup_of