Helpers for managing handlers of UIControl-based events and gesture recognizers.
The recommended way is to install using CocoaPods:
pod 'XCEViewEvents', '~> 1.1'
This library provides set of helper functions via extensions for UIControl
and UIView
classes. These functions are just syntax sugar on top of standard UIKit API.
For example, here is how to add handler to UIButton
instance button
for onTouchUpInside
("tap") event (assume we have an appropriate function called buttonTapHandler
on self
):
button.onTouchUpInside.add(
#selector(buttonTapHandler),
of: self
)
Alternatively, if self
conforms to HandlersOwner
protocol, the aboe example can be written like this:
self.bind(
#selector(buttonTapHandler),
with: button.onTouchUpInside
)
Same approach is used to bind handlers with gesture recognizers.
For example, here is how to add handler to UIImageView
instance image
for "tap" gesture (assume we have an appropriate function called tapGestureHandler
on self
):
image.onTapGesture.addRecognizer(#selector(tapGestureHandler), of: self){ gesture in
// configure gesture here
}
Alternatively, if self
conforms to HandlersOwner
protocol, the aboe example can be written like this:
self.bind(#selector(tapGestureHandler), with: image.onTapGesture){ gesture in
// configure gesture here
}