Cupcake
Cupcake copied to clipboard
How to solve flicker?
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()
This code will be a brief flicker effect after
After trying to setNeedsLayout(), layoutIfNeeded() also cannot solve
你好,看您的代码我发现了一些问题:
- .pin(.center) 跟 make.center.equal(bgView) 重复了,保留一个即可
- 设置了两次 make.right.equal(bgView),这会引起冲突
- make.right.equal(bgView) 跟 make.center.equal(bgView) 可能会引起冲突
- buttonStack里只有一个元素,可以直接用sureButton代替
- ImageView 没有设置宽高,这会引起页面跳到(不知道您说的flicker是不是指这个)
@nerdycat 谢谢指正, 但是 ImageView 设置了宽高比, contentView 设置了 fill ,显示出来没有问题,是还需要给 imageView 设置一个固定的宽高吗?
抱歉没注意到,那就不需要了。不知道您的问题解决了没?