使用snapkit更新约束上

问题描述:

我写了一个自定义的UIViewController类A和B类从A类使用snapkit更新约束上

A类是写在Objective-C继承了,所以它用砖石。 B类是用swift编写的,所以它使用snapkit。

在类AI中定义了子视图Aa的约束,然后我想更新B类中的子视图Aa的约束。但是我发现在B类中定义的新约束不起作用,Aa仍然使用在类中定义的约束A.

示例代码:

// class A.mm 
- (void)viewDidLoad { 
    [super viewDidLoad]; 

    self.Aa = [[UIView alloc] initWithFrame:CGZeroRect]; 
    [self.view addSubview:self.Aa]; 
    [self.Aa mas_makeConstraints:^(MASConstraintMaker *make) { 
    make.left.right.bottom.equalTo(self.view); 
    make.top.equalTo(self.view).offset(64); 
    }]; 
} 

// class B.swift 
override func viewDidLoad() { 
    super.viewDidLoad() 

    self.Aa.snp.updateConstraints { (make) in 
     make.left.right.bottom.equalToSuperview() 
     make.top.equalToSuperview().offset(108) 
    } 
} 

感谢您的帮助:]

予先删除子视图AA,并将其重新进行添加到B类和定义新的约束。

Remove all constraints affecting a UIView