ios - label已经在storyboard设置了约束,为什么label的constraints 为0?
ringa_lee
ringa_lee 2017-04-17 17:27:31
[iOS讨论组]

在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的约束:

ringa_lee
ringa_lee

ringa_lee

全部回复(3)
怪我咯

你在 viewWillAppear 中试试呢。

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

巴扎黑

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

黄舟

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

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号