Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to solve flicker? #10

Open
shengwanlin opened this issue Dec 28, 2018 · 4 comments
Open

How to solve flicker? #10

shengwanlin opened this issue Dec 28, 2018 · 4 comments

Comments

@shengwanlin
Copy link

shengwanlin commented Dec 28, 2018

    let bgView = View.bg(UIColor.c_mask_b)
    
    let contentView = View.bg("white").radius(Specs.metric.cornerRadius).pin(.center)
    contentView.addTo(bgView).makeCons({ (make) in
        make.right.equal(bgView).offset(Specs.metric.ratioMargin)
        make.right.equal(bgView).offset(-Specs.metric.ratioMargin)
        make.center.equal(bgView)
    })
    var stacks = [Any]()
    for (index, desc) in descs.enumerated() {
        var text = "\(index+1)"
        if !firstHasNo {
            text = "\(index)"
        }
        let icon = Button
            .bg(UIColor.c_tint)
            .str(text)
            .color("white")
            .font(Specs.font.small)
            .pin(.wh(16, 16))
            .radius(8)
        
        let label = Label
            .str(desc)
            .lines(0)
            .font(Specs.font.small)
            .color(UIColor.c_title)
        if !firstHasNo && index == 0 {
            stacks.append(
                HStack(label).align(.top)
            )
        } else {
            stacks.append(
                HStack(icon ,label).gap(Specs.metric.marginTen).align(.top)
            )
        }
        stacks.append(Specs.metric.marginTen)
    }
    
    let imgView = ImageView
        .bg("gray")
        .pin(.whRatio(1.86))
    let imgStack = HStack(Specs.metric.ratioMargin, imgView, Specs.metric.ratioMargin)
    
    let sureButton = Button
        .str("Được").color("white").font(Specs.font.llarge)
        .bg(UIColor.c_tint)
        .radius(Specs.metric.cornerRadius)
        .pin(.h(44.0))
    let buttonStack = HStack(sureButton)
    
    VStack(imgStack,
           Specs.metric.ratioMargin,
           stacks,
           Specs.metric.ratioMargin,
           buttonStack
        )
        .embedIn(contentView, Specs.metric.ratioMargin)
        .align(.fill)
    bgView.embedIn(UIApplication.shared.keyWindow!)
    bgView.setNeedsLayout()
    bgView.layoutIfNeeded()
@shengwanlin
Copy link
Author

This code will be a brief flicker effect after

After trying to setNeedsLayout(), layoutIfNeeded() also cannot solve

@nerdycat
Copy link
Owner

你好,看您的代码我发现了一些问题:

  1. .pin(.center) 跟 make.center.equal(bgView) 重复了,保留一个即可
  2. 设置了两次 make.right.equal(bgView),这会引起冲突
  3. make.right.equal(bgView) 跟 make.center.equal(bgView) 可能会引起冲突
  4. buttonStack里只有一个元素,可以直接用sureButton代替
  5. ImageView 没有设置宽高,这会引起页面跳到(不知道您说的flicker是不是指这个)

@shengwanlin
Copy link
Author

@nerdycat 谢谢指正, 但是 ImageView 设置了宽高比, contentView 设置了 fill ,显示出来没有问题,是还需要给 imageView 设置一个固定的宽高吗?

@nerdycat
Copy link
Owner

抱歉没注意到,那就不需要了。不知道您的问题解决了没?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants