🍃 UIView (HoverEvents)
Super easy hover gesture support for UIView (and UIView subclasses!)
- iPadOS 13.0+
- Mac Catalyst 13.0+
Swift (from ColorView.swift):
override func awakeFromNib() {
super.awakeFromNib()
// just one line of code!
self.tracksHoverEvents = true
}
Objective-C:
- (void)awakeFromNib {
[super awakeFromNib];
// still just one line of code!
[self setTracksHoverEvents:YES];
}
Swift (from TrackingView.swift):
override func cursorHoverBegan(_ pointInView: CGPoint) {
// ...
}
override func cursorHoverChanged(_ pointInView: CGPoint) {
// ...
}
override func cursorHoverEnded(_ pointInView: CGPoint) {
// ...
}
override func cursorHoverCancelled(_ pointInView: CGPoint) {
// ...
}
override func cursorHoverFailed(_ pointInView: CGPoint) {
// ...
}
Objective-C:
- (void)cursorHoverBegan:(CGPoint)pointInView {
// ...
}
- (void)cursorHoverChanged:(CGPoint)pointInView {
// ...
}
- (void)cursorHoverEnded:(CGPoint)pointInView {
// ...
}
- (void)cursorHoverCancelled:(CGPoint)pointInView {
// ...
}
- (void)cursorHoverFailed:(CGPoint)pointInView {
// ...
}
Swift:
self.hoveringBackgroundColor = UIColor.systemTeal
Objective-C:
[self setHoveringBackgroundColor:[UIColor systemTealColor]];
3️⃣: Don't forget to import the header file in your Bridging Header if you're using Swift!
(from HoverEvents-Bridging-Header.h):
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import "UIView+HoverEvents.h"
The demo app is built with Storyboards and the custom views are setup in ViewController.swift
Also here's a video demo I posted on my twitter: https://twitter.com/timdesir/status/1261178820335263744