Last active
July 27, 2022 15:48
-
-
Save steventroughtonsmith/eea3a62e58e1a34ee580276a180c54f5 to your computer and use it in GitHub Desktop.
UIKit right-click interaction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// RCGRightClickGestureRecognizer.swift | |
// RightClickGestureRecognizer | |
// | |
// Created by Steven Troughton-Smith on 27/07/2022. | |
// | |
import UIKit | |
class RCGRightClickInteraction: UIContextMenuInteraction { | |
class RCGRightClickGestureRecognizerDelegate: NSObject, UIContextMenuInteractionDelegate { | |
var parent:RCGRightClickInteraction? = nil | |
func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? { | |
parent?.handler(location) | |
return nil | |
} | |
} | |
var handler:(_:CGPoint) -> Void = { _ in } | |
let _delegate = RCGRightClickGestureRecognizerDelegate() | |
init(handler:@escaping (_:CGPoint) -> Void ) { | |
super.init(delegate: _delegate) | |
_delegate.parent = self | |
self.handler = handler | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment