gpt4 book ai didi

ios - NVActivityIndi​​catorView 仅适用于特定 View

转载 作者:搜寻专家 更新时间:2023-10-31 08:30:06 45 4
gpt4 key购买 nike

我正在使用这个库 https://github.com/ninjaprox/NVActivityIndicatorView用于显示加载指示器。默认情况下,它会阻止整个 View Controller ,但我如何才能只显示特定 View 的事件指示器。例如,如果一个 View Controller 包含一个 webview 和一些其他 View ,事件指示器应该只针对 webview,我应该能够与其他 View 交互。

class FaqViewController: UIViewController, UIWebViewDelegate
{

@IBOutlet var faqWebView: UIWebView!
static let activityData = ActivityData()
var activityIndicator : NVActivityIndicatorView!

override func viewDidLoad()
{
super.viewDidLoad()
faqWebView.delegate = self
faqWebView.loadRequest(URLRequest(url: URL(string: "https://www.google.com")!))
}

func webViewDidStartLoad(_ webView: UIWebView)
{
NVActivityIndicatorView.DEFAULT_BLOCKER_SIZE = CGSize(width: 45, height: 45)
NVActivityIndicatorPresenter.sharedInstance.startAnimating(FaqViewController.activityData)
}

func webViewDidFinishLoad(_ webView: UIWebView)
{
NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
}
}

最佳答案

例如显示activityIndi​​cator

func webViewDidStartLoad(_ webView: UIWebView)
{
//NVActivityIndicatorView.DEFAULT_BLOCKER_SIZE = CGSize(width: 45, height: 45)
//NVActivityIndicatorPresenter.sharedInstance.startAnimating(FaqViewController.activityData)

let xAxis = self.view.center.x // or use (view.frame.size.width / 2) // or use (faqWebView.frame.size.width / 2)
let yAxis = self.view.center.y // or use (view.frame.size.height / 2) // or use (faqWebView.frame.size.height / 2)



let frame = CGRect(x: (xAxis - 50), y: (yAxis - 50), width: 45, height: 45)
activityIndicator = NVActivityIndicatorView(frame: frame)
activityIndicator.type = . ballScale // add your type
activityIndicator.color = UIColor.red // add your color

self.view.addSubview(activityIndicator) // or use webView.addSubview(activityIndicator)
activityIndicator.startAnimating()
}

隐藏

func webView(_ webView: UIWebView, didFailLoadWithError error: Error)
{
hideactivityIndicator()
}

func webViewDidFinishLoad(webView: UIWebView!)
{
hideactivityIndicator()
}

func hideactivityIndicator()
{

activityIndicator. stopAnimating()
activityIndicator.removeFromSuperview()
}

关于ios - NVActivityIndi​​catorView 仅适用于特定 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46234193/

45 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com