简体   繁体   中英

How to disable 3D Touch Link Preview

Since iOS10 the " 3D Touch link preview " has been enabled by default, but how can I disable it in my app? Documentation says it's possible by setting allowsLinkPreview to false , but doing it separately for each use case is too much code. There must be an easier way, right?

I thought this would do it, but I get error "Property does not override any property from its superclass" . I hope there's just a small mistake, help would be appreciated:

extension WKWebView {
    override open var allowsLinkPreview: Bool {
        set {
            // no-op
        }
        get {
            return false
        }
    }
}

You could extend WKWebView with a convenience initializer and set the property inside of it. Then use this initializer to instantiate web views.

extension WKWebView {
    convenience init(allowsLinkPreview: Bool) {
        self.init()
        self.allowsLinkPreview = allowsLinkPreview
    }
}

Another option is to make a subclass of WKWebView and add this convenience initializer there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM