Skip to content

Instantly share code, notes, and snippets.

@agiletortoise
Created March 24, 2020 20:00
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agiletortoise/c692ae315586f0a5bf226b007132dafa to your computer and use it in GitHub Desktop.
Save agiletortoise/c692ae315586f0a5bf226b007132dafa to your computer and use it in GitHub Desktop.
PointerEnabledButton class demonstrating pointer support for iPadOS 13.4
import UIKit
class PointerEnabledButton: UIButton {
override init(frame: CGRect) {
super.init(frame: frame)
if #available(iOSApplicationExtension 13.4, *) {
enablePointer()
}
}
required init?(coder: NSCoder) {
super.init(coder: coder)
if #available(iOSApplicationExtension 13.4, *) {
enablePointer()
}
}
}
@available(iOSApplicationExtension 13.4, *)
extension PointerEnabledButton: UIPointerInteractionDelegate {
func enablePointer() {
self.addInteraction(UIPointerInteraction(delegate: self))
}
func pointerInteraction(_ interaction: UIPointerInteraction, regionFor request: UIPointerRegionRequest, defaultRegion: UIPointerRegion) -> UIPointerRegion? {
return defaultRegion
}
func pointerInteraction(_ interaction: UIPointerInteraction, styleFor region: UIPointerRegion) -> UIPointerStyle? {
return UIPointerStyle(effect: .automatic(.init(view: interaction.view!)))
}
}
@steipete
Copy link

@agiletortoise
Copy link
Author

Agreed. I didn't catch that in my initial digging. Still useful as a framework if you want to do anything other than the default behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment