Why touchesBegan is not firing?

I am really stumped. What could cause the touchesBegan() callback method of a view controller to not fire. Isn't that supposed to fire everytime a touch in the view controller is detected?

Answered by ShinehahGnolaum in 292605022

I got it.


Here's the solution:


It seems odd this code is needed at all. I would think that Apple would enable the desired behavior without having to write code for it. Perhaps there's a setting that does exactly what I need that I don't know about.


extension UIButton {
    open override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        super.touchesBegan(touches, with: event)
       
        next?.touchesBegan(touches, with: event)
       
        print("UIButton touchesBegan")
    }
   
    open override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
        super.touchesMoved(touches, with: event)
       
        next?.touchesMoved(touches, with: event)
       
        print("UIButton touchesMoved")
       
    }
   
    open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
        super.touchesEnded(touches, with: event)
       
        next?.touchesEnded(touches, with: event)
       
        print("UIButton touchesEnded")
       
    }
   
    open override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
        super.touchesCancelled(touches, with: event)
       
        next?.touchesCancelled(touches, with: event)
       
        print("UIButton touchesCancelled")
       
    }
   
    open override func touchesEstimatedPropertiesUpdated(_ touches: Set<UITouch>) {
        super.touchesEstimatedPropertiesUpdated(touches)
       
        next?.touchesEstimatedPropertiesUpdated(touches)
       
        print("UIButton touchesEstimatedPropertiesUpdated")
       
    }
}

userInteraction enabled for that view?


Is that view controller inside another view?


Using a clearColor background?

Accepted Answer

I got it.


Here's the solution:


It seems odd this code is needed at all. I would think that Apple would enable the desired behavior without having to write code for it. Perhaps there's a setting that does exactly what I need that I don't know about.


extension UIButton {
    open override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        super.touchesBegan(touches, with: event)
       
        next?.touchesBegan(touches, with: event)
       
        print("UIButton touchesBegan")
    }
   
    open override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
        super.touchesMoved(touches, with: event)
       
        next?.touchesMoved(touches, with: event)
       
        print("UIButton touchesMoved")
       
    }
   
    open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
        super.touchesEnded(touches, with: event)
       
        next?.touchesEnded(touches, with: event)
       
        print("UIButton touchesEnded")
       
    }
   
    open override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
        super.touchesCancelled(touches, with: event)
       
        next?.touchesCancelled(touches, with: event)
       
        print("UIButton touchesCancelled")
       
    }
   
    open override func touchesEstimatedPropertiesUpdated(_ touches: Set<UITouch>) {
        super.touchesEstimatedPropertiesUpdated(touches)
       
        next?.touchesEstimatedPropertiesUpdated(touches)
       
        print("UIButton touchesEstimatedPropertiesUpdated")
       
    }
}
Why touchesBegan is not firing?
 
 
Q