gpt4 book ai didi

ios - UIActivityIndi​​catorView 未显示在 web View 中

转载 作者:行者123 更新时间:2023-11-28 12:07:45 25 4
gpt4 key购买 nike

我有一个要添加 UIViewController 的 UINavigationController。在我的 UIViewController 中,我有一个 webview,并且还试图设置一个 UIActivityIndi​​catorView。但是我似乎无法让 UIActivityIndi​​catorView 显示出来。任何帮助都会很棒!

class TestWebViewController: UIViewController {

var loadSpinner: UIActivityIndicatorView!

var webView: UIWebView!

var title: String?

init(title: String?) {
self.title = title

self.webView = UIWebView(frame: CGRect.zero)
super.init(nibName: nil, bundle: nil)
commonInit()
}

func commonInit() {
loadSpinner = UIActivityIndicatorView(activityIndicatorStyle: .gray)
loadSpinner.center = webView.center
view.addSubview(loadSpinner)
webView.delegate = self
view = webView
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

UINavigationController(rootViewController: testWebViewController)

即使我尝试将 loadSpinner 添加到 webView,它也不会出现 webView.addSubview(loadSpinner)

最佳答案

结果: enter image description here

代码:

class ViewController: UIViewController {

var loadSpinner: UIActivityIndicatorView!
var webView: UIWebView!

override func viewDidLoad() {
super.viewDidLoad()

self.webView = UIWebView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))

loadSpinner = UIActivityIndicatorView(activityIndicatorStyle: .gray)

webView.addSubview(loadSpinner)

view = webView

loadSpinner.startAnimating()
}

override func viewDidLayoutSubviews() {
loadSpinner.center = webView.center
}
}

关于ios - UIActivityIndi​​catorView 未显示在 web View 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49078157/

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