Reputation: 283
Hi everyone (why my greeting message is always deleted ??? !!! )
Even I read many topics about it, I didn't find a proper answer about my issue.
I would like to know if it's possible to disable a long press event on a wkwebview window or detect when the user use a long press event to do whatever I want?
Actually I would like to copy an image link from a web site into a variable by using long press event and I don't want the popup to be called at all.
I'm using Swift
Thank you for your help !
Upvotes: 9
Views: 4444
Reputation: 183
For iOS 16:
@available(iOS 16.0, *)
func swizzleiOS16() {
guard let cls = NSClassFromString("UIEditMenuInteraction") else { return }
let originalSelector = NSSelectorFromString("presentEditMenuWithConfiguration:")
let swizzledSelector = #selector(UIEditMenuInteraction.presentEditMenuWithConfigurationHijack)
let originMethod = class_getInstanceMethod(cls, originalSelector)
let swizzleMethod = class_getInstanceMethod(UIEditMenuInteraction.self, swizzledSelector)
if let swizzledMethod = swizzleMethod, let originalMethod = originMethod{
method_exchangeImplementations(originalMethod, swizzledMethod)
}
}
@available(iOS 16.0, *)
extension UIEditMenuInteraction{
@objc func presentEditMenuWithConfigurationHijack() {
}
Upvotes: 0
Reputation: 2699
just hijack
the relevant,
func swizzle(){
guard let cls = NSClassFromString("UITextSelectionView") else { return }
let originalSelector = NSSelectorFromString("updateSelectionRects")
let swizzledSelector = #selector(UIView.updateSelectionRectsHijack)
let originMethod = class_getInstanceMethod(cls, originalSelector)
let swizzleMethod = class_getInstanceMethod(UIView.self, swizzledSelector)
if let swizzledMethod = swizzleMethod, let originalMethod = originMethod{
method_exchangeImplementations(originalMethod, swizzledMethod)
}
}
extension UIView{
@objc func updateSelectionRectsHijack(){ }
}
swizzle()
should be call just once.
What is UITextSelectionView
?
Check View Hierarchy
,
What is method updateSelectionRects
?
via runtime
,
import ObjectiveC
{
var count: UInt32 = 0
guard let methodArr = class_copyMethodList(NSClassFromString("UITextSelectionView"), &count) else { return }
let cnt = Int(count)
for i in 0..<cnt{
let method = methodArr[i]
let name = method_getName(method)
if let type = method_getTypeEncoding(method){
print(name, String(utf8String: type) ?? " _ | _ ")
}
}
}
Upvotes: 1
Reputation: 4037
you can use this to disable the pop up
view, while the highlighting is still there
func swizzle() {
guard let cls = NSClassFromString("UICalloutBar") else { return }
let originalSelector = NSSelectorFromString("appear")
let swizzledSelector = #selector(UIView.appearHijack)
let originMethod = class_getInstanceMethod(cls, originalSelector)
let swizzleMethod = class_getInstanceMethod(UIView.self, swizzledSelector)
if let swizzledMethod = swizzleMethod, let originalMethod = originMethod{
method_exchangeImplementations(originalMethod, swizzledMethod)
}
}
extension UIView{
@objc func appearHijack(){
}
}
swizzle()
should be call once only.
How I know UICalloutBar
?
Just use break point
, also bt
is an option.
Upvotes: 1