Cupcake icon indicating copy to clipboard operation
Cupcake copied to clipboard

How to solve flicker?

Open shengwanlin opened this issue 5 years ago • 4 comments

    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 avatar Dec 28 '18 10:12 shengwanlin

This code will be a brief flicker effect after

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

shengwanlin avatar Dec 28 '18 10:12 shengwanlin

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

  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是不是指这个)

nerdycat avatar Jan 14 '19 03:01 nerdycat

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

shengwanlin avatar Jan 15 '19 03:01 shengwanlin

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

nerdycat avatar Jan 15 '19 06:01 nerdycat