簡單的動畫就是把更改位置這件事放在一個時間里刹帕,所以重新修改約束吵血,更新約束,設置全局約束更改值偷溺。
UIWindow *window = [[UIApplication sharedApplication]keyWindow];
[window addSubview:self];
[self mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(window);
}];
// 在動畫開始之前 要強制刷新布局 如果不這樣的話前面的所有的布局設置都會在動畫中顯現出來
[self.superview layoutIfNeeded];
[UIView animateWithDuration:0.5 animations:^{
[self.contentView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self);
make.bottom.equalTo(self);
make.height.equalTo(@450);
}];
// 在動畫中刷新布局
[self.superview layoutIfNeeded];
}];