UIView和Masonry实现动画效果
Masonry 实现动画效果如下:
//button点击方法
- (void)clickedButton
{
static BOOL isMove; //默认是NO
Weakify(weakSelf);
//告诉self.view约束需要更新
[weakSelf.view setNeedsUpdateConstraints];
//调用此方法告诉self.view检测是否需要更新约束,若需要则更新,下面添加动画效果才起作用
[weakSelf.view updateConstraintsIfNeeded];
if (isMove) {
isMove = NO;
//添加动画
[UIView animateWithDuration:5 animations:^{
[weakSelf.displayView mas_updateConstraints:^(MASConstraintMaker *make) {
//更改距顶上的高度
make.top.equalTo(weakSelf.baseView.mas_bottom).with.offset(100);
}];
//必须调用此方法,才能出动画效果
[weakSelf.view layoutIfNeeded];
}];
}
else{
isMove = YES;
//添加动画
[UIView animateWithDuration:5 animations:^{
[weakSelf.displayView mas_updateConstraints:^(MASConstraintMaker *make) {
//更改距顶上的高度
make.top.equalTo(weakSelf.baseView.mas_bottom).with.offset(-100);
}];
//必须调用此方法,才能出动画效果
[weakSelf.view layoutIfNeeded];
}];
}
}重点说明:
相关推荐
云端漂移 2020-07-17
冰蝶 2020-04-20
wangdaren 2020-01-14
山兔与孟婆 2019-12-15
山兔与孟婆 2019-12-14
Ladyseven 2020-10-22
mapaler 2020-07-17
淡风wisdon大大 2020-06-27
lanzhusiyu 2020-06-21
AlisaClass 2020-06-05
jiedinghui 2020-06-04
usepython 2020-05-31
flycony 2020-05-30
88284453 2020-05-09
hqulyc 2020-05-05
yaodilu 2020-04-30
vavid 2020-04-20
AlisaClass 2020-04-11