Xcode VisualEffectView防止与其他视图交互

时间:2019-02-26 01:33:45

标签: ios swift xcode webview effect

我的应用程序具有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()
}
}

1 个答案:

答案 0 :(得分:1)

尝试将SELECT * FROM table_name WHERE something ORDER BY CASE WHEN :edate > :sdate THEN ddate ELSE NULL END, CASE WHEN :edate > :sdate THEN NULL ELSE department END; 中的isUserInteractionEnabled设置为false。

UIVisualEffectView

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