Preface
I have been a little idle recently and decided to add the knowledge I missed before, and then I found out how to implement animation when using Masonry? So after practicing and searching for relevant methods, I finally found the right way, hoping to provide some help to those in need.
text
Simply put, Masonry's animation usage is the same as normal animation usage. It can be achieved through the method of UIView animateWithDuration:<#(NSTimeInterval)#> animations:<#^(void)animations#>. Then the focus is on modifying constraints and the effectiveness of animations.
Modify constraints
There are two ways to modify constraints
Method 1
The first one is to use it directly
[Controls mas_updateConstraints:^(MASConstraintMaker *make) { }];
, just write a new constraint in the block
Method 2
It is to add global constraints, then assign values when adding constraints, and change values in the animation code.
@property (nonatomic, strong) MASConstraint *rightConstraint;
Code to add constraints:
[Controls mas_makeConstraints:^(MASConstraintMaker *make) { _rightConstraint=.mas_equalTo(view.mas_right).offset(-20); }];
Code to modify constraints in animation
.mas_equalTo(-100);
The above is how to modify the constraints.
Animation takes effect
Unlike general animations, using Masonry to put it in the block of the animation cannot directly make the animation take effect, but it directly causes the control to shift. After trying, the following operations should be added.
-(void)beginAnimate{ //Inform the constraints need to be changed[ setNeedsUpdateConstraints]; [UIView animateWithDuration:3 animations:^{ [btn mas_updateConstraints:^(MASConstraintMaker *make) { .mas_equalTo(view.mas_right).offset(-100); }]; //Inform the parent class control to draw, the code without comments cannot take effect[ layoutIfNeeded]; }]; }
The above article on how to perform animation operations when using Masonry on iOS is all the content I share with you. I hope you can give you a reference and I hope you can support me more.