我的应用程序具有wkwebview,并且设置了一个弹出窗口以显示应用程序信息。我使用youtube上的教程添加了visualeffectview。效果很好,现在出现的问题似乎是阻止我与Webview交互。我认为这与子视图的处理方式有关。但是我不确定该如何解决。

import UIKit
import WebKit
import SafariServices

class ViewController: UIViewController, WKNavigationDelegate {

var effect:UIVisualEffect!

@IBOutlet var webView: WKWebView!

@IBOutlet var activityIndicator: UIActivityIndicatorView!

@IBOutlet weak var visualEffectView: UIVisualEffectView!

override func viewDidLoad() {
    super.viewDidLoad()
    self.aboutPopOver.layer.cornerRadius = 10

    effect = visualEffectView.effect
    visualEffectView.effect = nil

    webView.navigationDelegate = self

    activityIndicator.startAnimating()
    activityIndicator.isHidden = true
    activityIndicator.hidesWhenStopped = true

    let url = Bundle.main.url(forResource: "Web/bulk_material_table", withExtension: "html")!
    webView.loadFileURL(url, allowingReadAccessTo: url)
    let request = URLRequest(url: url)
    self.webView.load(request)


}

func animateIn() {
    aboutPopOver.center = self.view.center

    aboutPopOver.transform = CGAffineTransform.init(scaleX: 1.3, y: 1.3)
    aboutPopOver.alpha = 0

    UIView.animate(withDuration: 0.4) {
        self.visualEffectView.effect = self.effect
        self.aboutPopOver.alpha = 1
        self.aboutPopOver.transform = CGAffineTransform.identity
    }

}


func animateOut () {
    UIView.animate(withDuration: 0.3, animations: {
        self.aboutPopOver.transform = CGAffineTransform.init(scaleX: 1.3, y: 1.3)
        self.aboutPopOver.alpha = 0

        self.visualEffectView.effect = nil

    }) { (success:Bool) in
        self.aboutPopOver.removeFromSuperview()
    }
}

func showActivityIndicator(show: Bool) {
    if show {
        activityIndicator.startAnimating()
    } else {
        activityIndicator.stopAnimating()
    }
}

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
    showActivityIndicator(show: false)
}

func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
    showActivityIndicator(show: true)
}

func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
    showActivityIndicator(show: false)
}

@IBAction func openURL(_ sender: Any) {

    guard let url = URL(string: "https://hapman.com") else {
        return
    }

    let safariVC = SFSafariViewController(url: url)
    present(safariVC, animated: true, completion: nil)
}

@IBOutlet var aboutPopOver: UIView!

@IBAction func aboutPopButton(_ sender: Any) {

 self.view.addSubview(aboutPopOver)
    aboutPopOver.center = self.view.center
    animateIn()
}

@IBAction func donePopButton(_ sender: Any) {

    self.aboutPopOver.removeFromSuperview()
    animateOut()
}
}

最佳答案

尝试将isUserInteractionEnabled中的UIVisualEffectView设置为false。

visualEffectView.isUserInteractionEnabled = false
isUserInteractionEnabledUIView的继承属性。虽然在某些子类(例如UILabel)上默认将其关闭,但在true上将其设置为UIVisualEffectView

10-07 18:35