Created
May 31, 2017 16:36
-
-
Save wh1pch81n/01d953377030721f1ec3db5332b0ffc8 to your computer and use it in GitHub Desktop.
triggering a UITapGestureRecognizer of a view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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