ios WKWebView:如何更改长按操作或禁用它?

pod7payv  于 2023-01-14  发布在  iOS
关注(0)|答案(3)|浏览(277)
    • 大家好**(为什么我的问候语总是被删除???!!)

即使我读了很多关于它的主题,我也没有找到一个合适的答案。
我想知道是否有可能禁用wkwebview窗口上的长按事件或检测用户何时使用长按事件来做任何我想做的事情?
事实上我想从一个网站复制一个图像链接到一个变量使用长按事件,我不希望弹出窗口被调用。
我用的是"斯威夫特"
谢谢你的帮助!

siv3szwd

siv3szwd1#

你可以使用这个来禁用pop up视图,而突出显示仍然存在

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的?
只需使用break point,也可以使用bt

0wi1tuuw

0wi1tuuw2#

仅仅是相关的,

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) ?? " _ | _ ")
            }
        }
   }
gzszwxb4

gzszwxb43#

适用于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() {
}

相关问题