有没有人知道如何在重新加载某个部分时闪烁自定义部分页眉/页脚视图?
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")
标题视图永远不会闪烁任何形式的修改,这是我想要的。但是,我使用自定义边距并在标题中添加图标,这就是为什么我需要自定义视图作为页眉/页脚。是否有一个我没有在.onSetupView上设置的属性可以解决这个问题?
答案 0 :(得分:0)
您的问题与您的header
视图一次又一次重新加载有关,并反复调整其框架,因此您只需添加bool
变量即可解决此问题
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
}
我希望这可以帮助你,问候