gpt4 book ai didi

ios - 每次向下滚动时如何在 UITableView 上居中显示加载 View ?

转载 作者:行者123 更新时间:2023-11-28 15:21:46 24 4
gpt4 key购买 nike

下面是我使用的代码,它在普通屏幕上工作正常,但是当我在表格 View 上向下滚动时,加载 View 加载但停留在顶部。每次向下滚动时,如何在 UITableView 上居中显示加载 View ?

extension UIViewController {
func loadWave(_ status: Bool) {
var fadeView: UIView?

if status == true {
fadeView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
fadeView?.backgroundColor = UIColor.clear
fadeView?.alpha = 0
fadeView?.tag = 99

let statusBarHeight: CGFloat = 20
let navBarHeight: CGFloat = 44
let image = UIImage(named: "image")
loadingWaveView = UIImageView(image: image)
loadingWaveView.center = view.center
loadingWaveView.frame = CGRect(x: (UIScreen.main.bounds.width / 2) - (112 / 2), y: (UIScreen.main.bounds.height / 2) - (63 / 2) - statusBarHeight - navBarHeight, width: 112, height: 63)
view.addSubview(fadeView!)
fadeView?.addSubview(loadingWaveView)

fadeView?.fadeTo(alphaValue: 1, withDuration: 0.2)
} else {
for subview in view.subviews {
if subview.tag == 99 {
UIView.animate(withDuration: 0.2, animations: {
subview.alpha = 0
}, completion: { (finished) in
subview.removeFromSuperview()
})
}
}
}
}
}

最佳答案

您应该设置Autolayout constraints 使其保持在中间。

fadeView?.addSubview(loadingWaveView)
loadingWaveView.translatesAutoresizingMaskIntoConstraints = false
let horizontalConstraint = NSLayoutConstraint(item: loadingWaveView, attribute: NSLayoutAttribute.centerX, relatedBy: NSLayoutRelation.equal, toItem: view, attribute: NSLayoutAttribute.centerX, multiplier: 1, constant: 0)
view.addConstraint(horizontalConstraint)
let verticalConstraint = NSLayoutConstraint(item: loadingWaveView, attribute: NSLayoutAttribute.centerY, relatedBy: NSLayoutRelation.equal, toItem: view, attribute: NSLayoutAttribute.centerY, multiplier: 1, constant: 0)
view.addConstraint(verticalConstraint)

关于ios - 每次向下滚动时如何在 UITableView 上居中显示加载 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45871400/

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