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

标签 ios swift eureka-forms

有人知道如何在重新加载部分时闪烁来获取自定义部分页眉/页脚 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/

相关文章:

ios - 无法在 SWIFT 中的方法之外保留数组数据

ios - 如何以编程方式向 Eureka 中的表单添加顶部导航?

ios - 当用户在 iOS 中拍照时,如何放置一种引导蒙版?

ios - 获取应用程序本身的 iOS iTunes App Store ID?

ios - 取消当前拖动 View 的长手势?

ios - 滚动时 UITableViewCell 自动布局抖动的动态单元格高度问题

swift3 - Eureka Forms Multiple Selector Row 设置默认值

swift - 隐藏字段未以 Eureka swift 形式提交其值

ios - 闭包语法中的 Swift weak Self

android - Firebase AB 测试 iOS 用户定位应用程序版本不起作用