0

有谁知道如何在重新加载部分时通过闪烁来获取自定义部分的页眉/页脚视图?

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 上设置的属性来解决这个问题?

4

1 回答 1

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
        }

我希望这对你有帮助,问候

于 2016-06-29T14:15:49.493 回答