1.控件的原始约束
self.animationBtn = [UIButtonbuttonWithType:UIButtonTypeSystem];
[self.animationBtnsetTitle:@"动画按钮"forState:UIControlStateNormal];
self.animationBtn.backgroundColor=[UIColorgrayColor];
[self.animationBtnaddTarget:selfaction:@selector(onGrowButtonTaped:)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:self.animationBtn];
self.scacle =1.0;
[self.animationBtnmas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self.view);
make.width.height.mas_equalTo(100);
make.width.height.lessThanOrEqualTo(self.view);
}];
2.点击开始做动画的时候从新做约束- (void)onGrowButtonTaped:(UIButton *)sender {
[UIViewanimateWithDuration:2animations:^{
[self.animationBtnmas_remakeConstraints:^(MASConstraintMaker *make){
make.left.top.equalTo(self.view);
make.width.height.mas_equalTo(200);
}];
[self.viewlayoutIfNeeded];//强制绘制
}];
}