Xcode VisualEffectView 阻止与其他视图交互
Xcode VisualEffectView preventing interaction with other views
我的应用程序有一个 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()
}
}
尝试将 UIVisualEffectView
的 isUserInteractionEnabled
设置为 false。
visualEffectView.isUserInteractionEnabled = false
isUserInteractionEnabled
是从 UIView
继承的 属性。虽然它在 UILabel
等子类上默认关闭,但在 UIVisualEffectView
.
上设置为 true
我的应用程序有一个 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()
}
}
尝试将 UIVisualEffectView
的 isUserInteractionEnabled
设置为 false。
visualEffectView.isUserInteractionEnabled = false
isUserInteractionEnabled
是从 UIView
继承的 属性。虽然它在 UILabel
等子类上默认关闭,但在 UIVisualEffectView
.
true