@@ -8,56 +8,120 @@ open class Responder {
8
8
9
9
/// Returns the next responder in the responder chain, or `nil` if there is no
10
10
/// next responder.
11
- public var next : Responder ? { nil }
11
+ open var next : Responder ? { nil }
12
12
13
13
/// Indicates whether this object is the first responder.
14
- public var isFirstResponder : Bool { return self . next === self }
14
+ open var isFirstResponder : Bool { return self . next === self }
15
15
16
16
/// Indiciates whether ths object can become the first responder.
17
- public var canBecomeFirstResponder : Bool { false }
18
-
19
- /// Indicates whether this object is willing to relinquish first-responder
20
- /// status.
21
- public var canResignFirstResponder : Bool { true }
17
+ open var canBecomeFirstResponder : Bool { false }
22
18
23
19
/// Results to make this object the first responder in its window.
24
- public func becomeFirstResponder( ) -> Bool {
20
+ open func becomeFirstResponder( ) -> Bool {
25
21
guard !self . isFirstResponder else { return true }
26
22
guard self . canBecomeFirstResponder else { return false }
27
23
return true
28
24
}
29
25
26
+ /// Indicates whether this object is willing to relinquish first-responder
27
+ /// status.
28
+ open var canResignFirstResponder : Bool { true }
29
+
30
30
/// Notifies the object that it has been asked to relinquish its status as
31
31
/// first responder in its window.
32
- public func resignFirstResponder( ) -> Bool {
32
+ open func resignFirstResponder( ) -> Bool {
33
33
return true
34
34
}
35
35
36
36
// MARK - Responding to Touch Events
37
37
38
38
/// Informs the responder that one or more new touches occurrd in a view or a
39
39
/// window.
40
- public func touchesBegan( _ touches: Set < Touch > , with event: Event ? ) {
40
+ open func touchesBegan( _ touches: Set < Touch > , with event: Event ? ) {
41
41
}
42
42
43
43
/// Informs the responder when one or more touches associated with an event
44
44
/// changed.
45
- public func touchesMoved( _ touches: Set < Touch > , with event: Event ? ) {
45
+ open func touchesMoved( _ touches: Set < Touch > , with event: Event ? ) {
46
46
}
47
47
48
48
/// Informs the responder when one or more fingers are raised from a view or a
49
49
/// window.
50
- public func touchesEnded( _ touches: Set < Touch > , with event: Event ? ) {
50
+ open func touchesEnded( _ touches: Set < Touch > , with event: Event ? ) {
51
51
}
52
52
53
53
/// Informs the responder when a system event (such as a system alert) cancels
54
54
/// a touch sequence.
55
- public func touchesCancelled( _ touches: Set < Touch > , with event: Event ? ) {
55
+ open func touchesCancelled( _ touches: Set < Touch > , with event: Event ? ) {
56
56
}
57
57
58
58
/// Tells the responder that updated values were received for previously
59
59
/// estimated properties or that an update is no longer expected.
60
- public func touchesEstimatedPropertiesUpdated( _ touches: Set < Touch > ) {
60
+ open func touchesEstimatedPropertiesUpdated( _ touches: Set < Touch > ) {
61
+ }
62
+
63
+ // MARK - Responding to Motion Events
64
+
65
+ /// Tells the receiver that a motion event has begun.
66
+ open func motionBegan( _ motion: Event . EventSubtype , with event: Event ? ) {
67
+ }
68
+
69
+ /// Tells the receiver that a motion event has ended.
70
+ open func motionEnded( _ motion: Event . EventSubtype , with event: Event ? ) {
71
+ }
72
+
73
+ /// Tells the receiver that a motion event has been cancelled.
74
+ open func motionCancelled( _ motion: Event . EventSubtype , with event: Event ? ) {
75
+ }
76
+
77
+ // MARK - Responding to Press Events
78
+
79
+ /// NOTE: Generally, responders that handle press events should override all
80
+ /// four of these methods.
81
+
82
+ /// Tells this object when a physical button is first pressed.
83
+ open func pressesBegan( _ presses: Set < Press > , with event: PressesEvent ? ) {
84
+ }
85
+
86
+ /// Tells this object when a value associated with a press has changed.
87
+ open func pressesChanged( _ presses: Set < Press > , with event: PressesEvent ? ) {
88
+ }
89
+
90
+ /// Tells the object when a button is released.
91
+ open func pressesEnded( _ presses: Set < Press > , with event: PressesEvent ? ) {
92
+ }
93
+
94
+ /// Tells this object when a system event (such as a low-memory warning) cancels a press event.
95
+ open func pressesCancelled( _ presses: Set < Press > , with event: PressesEvent ? ) {
96
+ }
97
+
98
+ // MARK - Responding to Remote-Control Events
99
+
100
+ /// Tells the object when a remote-control event is received.
101
+ open func remoteControlReceived( with event: Event ? ) {
102
+ }
103
+
104
+ // MARK - Managing Input Views
105
+
106
+ /// The custom input view to display when the receiver becomes the first
107
+ /// responder.
108
+ open private( set) var inputView : View ?
109
+
110
+ /// The custom input view controller to use when the receiver becomes the
111
+ /// first responder.
112
+ open private( set) var inputViewController : InputViewController ?
113
+
114
+ /// The custom input accessory view to display when the receiver becomes the
115
+ /// first responder.
116
+ open private( set) var inputAccessoryView : View ?
117
+
118
+ /// The custom input accessory view controller to display when the receiver
119
+ /// becomes the first responder.
120
+ open private( set) var inputAccessoryViewController : InputViewController ?
121
+
122
+ /// Updates the custom input and accessory views when the object is the first
123
+ /// responder.
124
+ open func reloadInputViews( ) {
61
125
}
62
126
63
127
// MARK - Building and Validating Commands
@@ -68,11 +132,24 @@ open class Responder {
68
132
}
69
133
70
134
/// Asks the receiving responder to validate the command.
71
- open func validate( _ command: Command ) {
135
+ public func validate( _ command: Command ) {
72
136
self . next? . validate ( command)
73
137
}
74
138
75
- // MARK - Constants
139
+ /// Requests the receiving responder to enable or disable the specified
140
+ /// command in the user interface.
141
+ open func canPerformAction( _ action: ( AnyObject ) -> ( _: Action , _: Any ? ) -> Void ,
142
+ withSender sender: Any ? ) -> Bool {
143
+ fatalError ( " \( #function) not yet implemented " )
144
+ }
145
+
146
+ open func target( forAction action: ( AnyObject ) -> ( _: Action , _: Any ? ) -> Void ,
147
+ withSender sender: Any ? ) -> Any ? {
148
+ guard canPerformAction ( action, withSender: sender) else { return nil }
149
+ fatalError ( " \( #function) not yet implemented " )
150
+ }
151
+
152
+ // MARK - Responding to Keyboard Notifications
76
153
77
154
/// A user info key to retrieve the animation curve that the system uses to
78
155
/// animate the keyboard onto or off the screen.
0 commit comments