gpt4 book ai didi

ios - 如何防止自定义标题在部分更新时闪烁?

转载 作者:行者123 更新时间:2023-11-30 13:21:32 24 4
gpt4 key购买 nike

有人知道如何在重新加载部分时闪烁来获取自定义部分页眉/页脚 View 吗?

Section(header:"",footer:"") {section in
section.tag = "main"
var header = HeaderFooterView<GenericSection>(HeaderFooterProvider.Class)
header.onSetupView = { v,s in
v.label.frame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width - 30, height: 20 )
v.label.text = self.row.title
v.label.numberOfLines = 0
v.label.textAlignment = .Justified
v.label.font = UIFont.preferredFontForTextStyle(UIFontTextStyleHeadline)
v.label.textColor = UIColor(red:0.47, green:0.47, blue:0.49, alpha:1.0)
v.label.frame = v.label.bounds
v.label.sizeToFit()
v.bounds = CGRect(x: -8, y: -8, width: v.label.bounds.width - 15, height: v.label.bounds.height + 25)
}
section.header = header
section.footer = nil
}

如果我使用 Section(header:"test",footer:"test2") ,标题 View 在任何表单修改时都不会闪烁,这正是我想要的。但是,我使用自定义边距并向标题添加图标,这就是为什么我需要自定义 View 作为页眉/页脚。是否有我未在 .onSetupView 上设置的属性可以解决此问题?

最佳答案

您的问题与您的 header View 一遍又一遍地重新加载,并一遍又一遍地调整他的框架有关,因此您只需添加一个 bool 变量即可解决此问题像这样

有问题 enter image description here

没有问题enter image description here

class GenericSection: UIView {
let label = UILabel()
var positioned = false
override init(frame: CGRect) {
super.init(frame: frame)
label.frame = CGRect(x: 0,y: 0,width: self.bounds.size.width - 30, height: 40)
self.addSubview(label)
}

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

然后

form +++ Section(header:"",footer:"") {section in
section.tag = "main"
var header = HeaderFooterView<GenericSection>(HeaderFooterProvider.Class)
header.onSetupView = { v,s in
if(!v.positioned)
{
v.layer.borderColor = UIColor.redColor().CGColor
v.layer.borderWidth = 1
v.label.frame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width - 30, height: 20 )
v.label.text = "Testing Custom Header without issue"
v.label.numberOfLines = 0
v.label.textAlignment = .Justified
v.label.font = UIFont.preferredFontForTextStyle(UIFontTextStyleHeadline)
v.label.textColor = UIColor(red:0.47, green:0.47, blue:0.49, alpha:1.0)
v.label.frame = v.label.bounds
v.label.sizeToFit()
v.bounds = CGRect(x: -8, y: -8, width: v.label.bounds.width - 15, height: v.label.bounds.height + 25)
v.setNeedsLayout()
v.setNeedsDisplay()
v.positioned = true
}
}
section.header = header
section.footer = nil
}

希望这对您有帮助,问候

关于ios - 如何防止自定义标题在部分更新时闪烁?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37728329/

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