ios - 关于 layoutSubviews 中会不会调用 updateConstraintsIfNeeded
PHP中文网
PHP中文网 2017-04-18 09:46:14
0
0
572

在调用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级讲师

Antworte allen(0)
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!