滚动在WebView macOS中不可见 [英] Scroll not visible in WebView macOS

查看:250
本文介绍了滚动在WebView macOS中不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使滚动条在macView的WebView中不可见?

Is it possible to make the scroll not visible in WebView for macOS?

实施网络视图

我有一个从库到情节提要的WebView. 我有连接

I have a WebView from the library to the Storyboard I have the connection

 @IBOutlet weak var webView1: WKWebView!

我在ViewController.swift中:

I have in the ViewController.swift:

webView1.load(URLRequest(url: URL(string: "https:www.apple.com")!))

我尝试过的内容

我已经尝试了很多事情,但可以评论一下:

I have tried many things but it could be helpful to comment:

-iOS解决方案在macOS上不起作用:

-The iOS solution do not work in macOS:

webView1.scrollView.isScrollEnabled = false

-有些问题类似,但有所不同: OS X Swift WebView禁用滚动

- There are some questions similar, but different: OS X Swift WebView disable scrolling

他询问如何禁用WebView.请问如何使其不可见.实际上,我不介意是否禁用它.

He asks how to disable WebView. I ask how to make it not visible. In fact, I do not mind if it is disabled or not.

无论如何,我都尝试过该解决方案:

In any case, I have tried that solution:

webView1.mainFrame.frameView.allowsScrolling = false;

这给我一个错误:类型为"WKWebView"的值没有成员"mainFrame"

It gives me an error: Value of type 'WKWebView' has no member 'mainFrame'

推荐答案

webview.enclosingScrollView?.verticalScrollElasticity = .allowed
webview.enclosingScrollView?.horizontalScrollElasticity = .allowed
webview.enclosingScrollView?.scrollerKnobStyle = .dark // change it

某些Cocoa控件本身具有滚动视图,例如NSCollectionView等.上面的几行使您可以启用滚动,并且由于滚动已启用并且具有某种样式,因此可以使滚动可见.

Some of Cocoa controls has scrollView inside of itself like NSCollectionView and many more. The lines of above makes give you allow to scroll enabled and it gives scroll visible because of scroll has enable and it has some style.

如果要隐藏滚动指示器,则可以使用;

And if you want to hide scroll indicator you can use;

webview.enclosingScrollView?.horizontalScroller?.isHidden = true

这是水平的,您也必须将其设置为垂直.

This is for horizontal, you must set it with vertical too.

这篇关于滚动在WebView macOS中不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆