Search code examples
iosswiftuikit

TapGestureRecogniser doesn't work at all in the newly created UIViewController but works in all the old UIViewControllers made before


Proof that gesture is being added but not detected

import UIKit

class PlaybackSpeedController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        view.isUserInteractionEnabled = true
        let tap = UITapGestureRecognizer(target: self, action: #selector(tapDetected(_:)))
        view.addGestureRecognizer(tap)
    }
    
    @objc func tapDetected(_ tap : UITapGestureRecognizer){
        print("hello")
    }
}

This hello never gets triggered. what am I missing? Funny how I used to play with gestures but don't understand why this happens


Solution

  • Setting the UIViewController's view.backgroundColor property to be some colour instead of default one solved the issue for me