自动布局框架x位置在打印时不正确

我有带有子视图的UIView,在其中设置了这样的自动布局:

    label1Container.topAnchor.constraint(equalTo: topAnchor),label1Container.bottomAnchor.constraint(equalTo: bottomAnchor),label1Container.leftAnchor.constraint(equalTo: leftAnchor),label2Container.topAnchor.constraint(equalTo: topAnchor),label2Container.bottomAnchor.constraint(equalTo: bottomAnchor),label2Container.rightAnchor.constraint(equalTo: rightAnchor),label2Container.leftAnchor.constraint(equalTo: label1Container.rightAnchor),label1Container.widthAnchor.constraint(equalTo: label2Container.widthAnchor),

然后我尝试获取label2Container框架:

override func layoutSubviews() {
            super.layoutIfNeeded()
            print("c1: \(label1Container.frame),c2: \(label2Container.frame)")

结果是:

  

c1:(0.0,0.0,0.0,128.0),c2:(0.0,0.0,0.0,128.0)

但是在屏幕上它呈现的很好(紫色)。

自动布局框架x位置在打印时不正确

如何获得正确的镜框?

编辑: 好吧,愚蠢的我,我发现检查框架的适当位置是draw(frame:CGRect)

lixb07072014 回答:自动布局框架x位置在打印时不正确

尝试

override func layoutSubviews() {
   super.layoutSubviews()
   print("c1: \(label1Container.frame),c2: \(label2Container.frame)") 
}  

super.layoutSubviews()而不是super.layoutIfNeeded()

,

好吧,愚蠢的我,我发现检查框架的正确位置是#define REP(limit) for(int i = 0; i < limit; i++) #define REP2(limit2) for(int j = 0; i < limit2; j++) int main() { int testcases; cin>>testcases; while(testcases--){ int days,diet,current = 0; cin>>days>>diet; bool res = true; REP(days){ int x; cin>>x; cout<<" ss "; current += x; if(current < diet){ cout<<"NO "<<i+1; res = false; break; } current -= diet; } if(res == true){ cout<<"YES"; } } return 0; }

本文链接:https://www.f2er.com/3080944.html

大家都在问