大家好(为什么我的问候消息总是被删除???!!!)
尽管我查阅了许多与此相关的主题,但并未找到有关我的问题的适当答案。
我想知道是否可以禁用wkwebview窗口上的长按事件或检测用户何时使用长按事件来执行我想要的操作?
实际上,我想通过使用长按事件将网站上的图像链接复制到变量中,并且我根本不希望弹出菜单被调用。
我正在使用Swift
谢谢您的帮助!
大家好(为什么我的问候消息总是被删除???!!!)
尽管我查阅了许多与此相关的主题,但并未找到有关我的问题的适当答案。
我想知道是否可以禁用wkwebview窗口上的长按事件或检测用户何时使用长按事件来执行我想要的操作?
实际上,我想通过使用长按事件将网站上的图像链接复制到变量中,并且我根本不希望弹出菜单被调用。
我正在使用Swift
谢谢您的帮助!
弹出视图
,同时保留高亮显示。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()
应该仅被调用一次。
我怎么了解 UICalloutBar
?
只需使用断点
,同时bt
也是一个选项。
劫持
相关内容。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()
应该只调用一次。
UITextSelectionView
是什么?
检查View Hierarchy
,
方法updateSelectionRects
是什么意思?
通过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) ?? " _ | _ ")
}
}
}
对于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() {
}
UILongPressGestureRecognizer
添加到UIWebView
上,并在其上禁用actionSheet
。然后,在长按时,我的操作被触发,并且我在每次长按时在 WebView 顶部呈现一个新视图。 - Siavash Alp