首页 > label已经在storyboard设置了约束,为什么label的constraints 为0?

label已经在storyboard设置了约束,为什么label的constraints 为0?

在storyboard中在viewcontroller中添加了scrollview,在scrollview上面添加了context view,在context view上面添加了view,view上面添加了label,均设置了约束,然后在viewdidload 中 print(self.bodyTextLabel.constraints.count)结果显示是0,这是什么原因,还是说我哪里设置出现了问题?!

 self.imageView.removeFromSuperview()
            
            
            print(self.bodyTextLabel.constraints.count)
    
            for constraint in self.bodyTextLabel.constraints {
                if constraint.identifier == "LabelBottomToViewBottom" {
                    constraint.priority = 1000
                }
            }

在viewWillAppear也尝试了,发现打印出来constraints 还是0,整个项目,其他地方的view打印constrains打印都是0 。。。我也是醉了,莫非是storyboard设置什么出现了问题

context view 约束:


view 约束:


label的约束:


在viewwillappear中自动布局还没有生效,viewDidAppear中已经生效。一般有什么要调整的,我会放到viewWillLayoutSubview中。生命周期什么的没研究过,就不多打字了


你在 viewWillAppear 中试试呢。

viewDidLoad 中不要放置关于几何的代码,打印测试也是不准的。


虽然这种情况很少见,试一试点击XCode-Product-Clean把模拟器里安装的工程清一下,然后重新编译

【热门文章】
【热门文章】