https://github.com/xcessentials/viewevents
[DEPRECATED - use 'SwiftUI' instead] Helpers for managing handlers of UIControl-based events and gesture recognizers.
https://github.com/xcessentials/viewevents
chainable gesture-recognizer swift uicontrol uikit unified xcode
Last synced: 4 months ago
JSON representation
[DEPRECATED - use 'SwiftUI' instead] Helpers for managing handlers of UIControl-based events and gesture recognizers.
- Host: GitHub
- URL: https://github.com/xcessentials/viewevents
- Owner: XCEssentials
- License: mit
- Created: 2016-11-30T15:01:07.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-16T14:57:32.000Z (about 7 years ago)
- Last Synced: 2025-02-01T12:23:00.221Z (4 months ago)
- Topics: chainable, gesture-recognizer, swift, uicontrol, uikit, unified, xcode
- Language: Swift
- Homepage: https://xcessentials.github.io/ViewEvents/
- Size: 44.9 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/XCEssentials/ViewEvents/releases)
[](https://cocoapods.org/?q=XCEViewEvents)
[](https://cocoapods.org/?q=XCEViewEvents)
[](https://opensource.org/licenses/MIT)# Introduction
Helpers for managing handlers of UIControl-based events and gesture recognizers.
# How to install
The recommended way is to install using [CocoaPods](https://cocoapods.org/?q=XCEViewEvents):
```ruby
pod 'XCEViewEvents', '~> 1.1'
```# How it works
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.
# How to use
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`):
```swift
button.onTouchUpInside.add(
#selector(buttonTapHandler),
of: self
)
```Alternatively, if `self` conforms to `HandlersOwner` protocol, the aboe example can be written like this:
```swift
self.bind(
#selector(buttonTapHandler),
with: button.onTouchUpInside
)
```## Gesture recognizers
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`):
```swift
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:
```swift
self.bind(#selector(tapGestureHandler), with: image.onTapGesture){ gesture in
// configure gesture here
}
```