【问题标题】:Disable scrolling of WKWebView in NSScrollView在 NSScrollView 中禁用 WKWebView 的滚动
【发布时间】:2017-10-13 04:52:43
【问题描述】:

我想在 Swift 中禁用 macOS 上的 NSScrollView 内的 WKWebView 的滚动。

我找到了一种使用 css 禁用 WKWebView 内滚动的方法,但 WKWebView 仍然阻止 NSScrollView 滚动。

有人知道怎么做吗?

【问题讨论】:

    标签: objective-c macos scroll wkwebview nsscrollview


    【解决方案1】:

    子类WKWebView并实现以下方法:

    - (void)scrollWheel:(NSEvent *)event {
        // pass web view scroll events to the next responder. comment
        // this line out if you just want to disable scrolling 
        // altogether.
        //
        [[self nextResponder] scrollWheel:event];
    }
    

    【讨论】:

    • 这可能是 macOS 上 WKWebView 唯一可行的解​​决方案
    【解决方案2】:

    快速回答:

    public class NoScrollWKWebView: WKWebView {
        public override func scrollWheel(with theEvent: NSEvent) {
            nextResponder?.scrollWheel(with: theEvent)
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-05
      • 1970-01-01
      • 1970-01-01
      • 2015-04-22
      • 2016-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多