ios - 关于 layoutSubviews 中会不会调用 updateConstraintsIfNeeded
PHP中文网
PHP中文网 2017-04-18 09:46:14
[iOS讨论组]

在调用updateConstraintsIfNeeded可能会立即执行updateConstraints然后调用layoutSubviews,但是在layoutSubviews的时候会不会调用updateConstraintsIfNeeded呢?

比如说在viewDidLoad中初始化并布局了view,然后在viewDidAppear的时候更新了约束,这时候如果调用layoutIfNeeded,在layoutSubviews中会不会调用updateConstraintsIfNeeded呢?以下是一部分代码做个示范

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.cview = [[CustomView alloc] init];
    [self.view addSubview:self.cview];
    
    [NSLayoutConstraint constraintWithItem:view4 attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:view1 attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:8.0].active = YES;
}

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    [NSLayoutConstraint constraintWithItem:view4 attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:view1 attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0].active = YES;
    
    [self layoutIfNeeded];
}

网上有人说会,但是我自己试了下貌似并没有。
但是按照Autolayout布局的步骤,应该是先更新约束然后更新布局,在上面的例子中layoutIfNeeded直接调用了layoutSubviews,照理来说也应该去询问下是不是需要更新约束吧???
另外上面的代码中是不是不需要调用layoutIfNeeded,不调用也会更新

PHP中文网
PHP中文网

认证0级讲师

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

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