queue and dispatches for handling via sendEvent(_:) Event B Event C Event D • Forwards the event to the keyWindow, invoking the sendEvent(_:) method of the UIWindow object Event A UIWindow sendEvent(_:) UIApplication sendEvent(_:)
view where the touch occurred Event A Event B Event C Event D Event A UIControl hitTest(_:withEvent:) UIApplication sendEvent(_:) UIWindow sendEvent(_:)
view where the touch occurred Event A Event B Event C Event D UIApplication sendEvent(_:) Event A UIWindow sendEvent(_:) UIControl hitTest(_:withEvent:) • If the View is a UIControl, UIKit checks the target and action properties target: AnyObject, action: Selector
sendAction(_:to:from:forEvent:) • The message is forwarded to the control contained in the target property Event B Event C Event D UIApplication sendAction(_:to:from:forEvent:) UIControl doSomething(_:) target: UIControl, action: doSomething
on the target class, an NSInvalidArgumentException "unrecognized selector sent to instance" is thrown. Event B Event C Event D UIControl target: UIControl, action: doSomething UIApplication sendAction(_:to:from:forEvent:)
the event to the Responder Chain. UIControl target: nil, action: doSomething UIView UIViewController UIWindow AppDelegate • Starting at the First Responder the chain is traversed until the specified action message is encountered. UIApplication doSomething(_:) UIApplication sendAction(_:to:from:forEvent:)
application = UIApplication.sharedApplication() application.sendAction(“didReceiveTapGesture:", to: nil, // Send up the responder chain. from: self, // UIKit drops any action sent from UIGestureRecognizer forEvent: nil)
UIGestureRecognizer to access methods/properties let application = UIApplication.sharedApplication() application.sendAction(“didReceiveTapGesture:", to: nil, // Send up the responder chain. from: self, // UIKit drops any action sent from UIGestureRecognizer forEvent: nil)
uigesturerecognizer_and_nil-targeted_act • Cocoa Design Patterns by Erik M. Buck. Donald A. Yacktman. http://www.goodreads.com/book/show/ 3048265-cocoa-design-patterns • Apple documentation • Paul Goracke (@pgor)