0

As asked here: Pan gesture interferes with UISlider and Gesture problem: UISwipeGestureRecognizer + UISlider I cannot get UISlider to work with a pan gesture where in my navigation controller I have a class that has a "back" button capability.

The answers mention that I should add a delegate to my class as such

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
    if let view = touch.view, view == slider {
        return false
    }
    return true
}

However, this method never gets called. I have tried about 15 ways to set the delegate for this class, but I honestly have no clue what to set at the delegate.

let myScreenEdgePanGestureRecognizer = UIScreenEdgePanGestureRecognizer(target: self, action:nil)
myScreenEdgePanGestureRecognizer.delegate = self

Nothing to this effect works. Could someone clearly explain how I can fix this problem. I have tried every approach on the first 2 pages of google. Thank you.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
AlexK
  • 336
  • 8
  • 21
  • 41

2 Answers2

0

If you see this code more precisely, then code is checking class as a UISlider not object of UISlider.

So in swift you have to write like this

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
    let view = touch.view
    if  view is UISlider { // check class as a UISlider
        return false
    }
    return true
}

I didn't run and check my code, if any editing required then do and if you need any help then add comment.

Edit

For UIScreenEdgePanGestureRecognizer, check this post : https://www.hackingwithswift.com/example-code/uikit/how-to-detect-edge-swipes

dahiya_boy
  • 9,298
  • 1
  • 30
  • 51
  • Yes you're probably right but my issue is that the method never gets called. Also I'm not trying to add an action, so this post does not help. – AlexK Dec 04 '18 at 08:07
  • You need to add gesture on your view `view.addGestureRecognizer(myScreenEdgePanGestureRecognizer)` – dahiya_boy Dec 04 '18 at 09:11
0

Try to declare edges

In Swift it will looks like

let myScreenEdgePanGestureRecognizer = UIScreenEdgePanGestureRecognizer(target: self, action:nil)
myScreenEdgePanGestureRecognizer.delegate = self
myScreenEdgePanGestureRecognizer.edges = .left //.right, .top, .bottom
ChooGoo
  • 85
  • 8