简体   繁体   中英

iOS Swift GestureRecognizer not working

I try to Recognize User Taps on a View. I tried it with the following Code:

override func viewDidLoad() {
    super.viewDidLoad()
    let tap = UITapGestureRecognizer(target: self, action: #selector(doubleTapped))
    tap.numberOfTapsRequired = 2
    view.addGestureRecognizer(tap)


    let request = NSURLRequest(URL:URL!)
    self.webView.loadRequest(request)
    self.webView.delegate = self;

}

func doubleTapped(gesture:UIGestureRecognizer)) {
    // do something cool here
    print("tabbed")
}

But nothing happens, the Method doubleTapped is never called. Whats wrong here?

GestureRecognizer on main view will work in your case if there is no subviews.

You can add the tap Gesture to the topmost view if the subviews have same frame as main view to achieve the same functionality.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM