pretz
pretz

Reputation: 242

Xcode VisualEffectView preventing interaction with other views

My app has a wkwebview and I have set a popover to display app information. I added a visualeffectview using a tutorial from youtube. The effect works great, the problem is now it appears to prevent me from interacting with the webview. I think this has something to do with how the subviews are being handled. But I am not sure how to fix it.

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()
}
}

Upvotes: 1

Views: 184

Answers (1)

Shamas S
Shamas S

Reputation: 7549

Try setting isUserInteractionEnabled of your UIVisualEffectView to false.

visualEffectView.isUserInteractionEnabled = false

isUserInteractionEnabled is an inherited property from UIView. While it's switched off by default on some subclasses like UILabel, it's set to true on UIVisualEffectView.

Upvotes: 1

Related Questions