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];//强制绘制
}];
}
动画按钮大小变化
本文介绍了一个使用Masonry布局约束的动画按钮实现方法。通过修改按钮的宽度和高度约束,按钮可以在点击时放大并改变位置。文章详细展示了如何设置初始约束以及如何在动画过程中更新这些约束。
1万+

被折叠的 条评论
为什么被折叠?



