在WKWebView上启用/禁用UITabBar

时间:2019-06-13 05:25:56

标签: ios swift toolbar wkwebview

我的ToolBar有问题。 Unzwar我想使它们在向下滚动时消失,而在向上滚动时再次出现。不幸的是,互联网上的说明对我没有帮助,因为我用代码编写了WKWebView。这将采用完整视图,从而导致Cookie通知被截断,您无法确认。

这是我的代码:

import UIKit
import WebKit

class SecondViewController: UIViewController, WKUIDelegate, WKNavigationDelegate {

    @IBOutlet weak var activityIndicatorView: UIActivityIndicatorView!
    var webView : WKWebView!
    @IBOutlet weak var containerView: UIScrollView? = nil

    var url: String?
    var pageTitle: String?
    var requestUrl: String?

    override func viewDidLoad() {
        super.viewDidLoad()

        // add activity
        self.webView.addSubview(self.activityIndicatorView)
        self.activityIndicatorView.startAnimating()
        self.webView.navigationDelegate = self
        self.activityIndicatorView.hidesWhenStopped = true
    }

    override func loadView() {
        super.loadView()
        let webConfiguration = WKWebViewConfiguration()
        webView = WKWebView(frame: view.frame, configuration: webConfiguration)
        self.view.addSubview(self.webView)
        webView.isUserInteractionEnabled = true
        webView.allowsBackForwardNavigationGestures = true
        webView.load(URLRequest(url: URL(string: "EXAMPLE-URL")!))

    }

    func scrollViewWillBeginDragging(scrollView: UIScrollView) {
        if scrollView.panGestureRecognizer.translation(in: scrollView).y < 0{
            changeTabBar(hidden: true, animated: true)
        }
        else{
            changeTabBar(hidden: false, animated: true)
        }
    }

    func changeTabBar(hidden:Bool, animated: Bool){
        guard let tabBar = self.tabBarController?.tabBar else { return; }
        if tabBar.isHidden == hidden{ return }
        let frame = tabBar.frame
        let offset = hidden ? frame.size.height : -frame.size.height
        let duration:TimeInterval = (animated ? 0.5 : 0.0)
        tabBar.isHidden = false

        UIView.animate(withDuration: duration, animations: {
            tabBar.frame = frame.offsetBy(dx: 0, dy: offset)
        }, completion: { (true) in
            tabBar.isHidden = hidden
        })
    }

结果应为ToolBar的滚动WKWebView

有人可以帮助我吗?

提前谢谢

0 个答案:

没有答案