Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wh1pch81n/01d953377030721f1ec3db5332b0ffc8 to your computer and use it in GitHub Desktop.
Save wh1pch81n/01d953377030721f1ec3db5332b0ffc8 to your computer and use it in GitHub Desktop.
triggering a UITapGestureRecognizer of a view
for gr in view.gestureRecognizers ?? [] where gr is UITapGestureRecognizer
{
let tgr = gr as! UITapGestureRecognizer
if let _targets = tgr.value(forKey: "targets") as? NSArray {
let targets = _targets as [AnyObject]
for targetAction in targets {
if let desc = targetAction.value(forKey: "description") as? String
, let actionString = desc.components(separatedBy: ",")[0].components(separatedBy: "=").last
, let target = targetAction.value(forKey: "target") as? NSObject
{
if actionString.contains(":") {
target.perform(NSSelectorFromString(actionString), with: tgr)
} else {
target.perform(NSSelectorFromString(actionString))
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment