How do I convert MASConstraint to NSLayoutConstraint?

I am currently using "Freemasonry" and "POP" in my application. I am wondering how to revive the restriction created by Freemasonry? So here's my code:

[imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo([NSValue valueWithCGSize:CGSizeMake(ScreenWidth, ScreenHeight)]);
        make.top.equalTo(self.mas_top);
    }];

      

So this is a simple example. When POP animates the limit change, it needs something like this (I keep some codes here):

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *containerHeightConstraint;
[self.containerHeightConstraint pop_addAnimation:spring forKey:@"spring"];

      

I have no problem getting these two libraries to work separately, but I'm wondering how to animate the MASConstraint change, because the POP needs to take NSLayoutConstraint as a parameter as stated in the documentation. So the question is, how do I convert the MASConstraint to NSLayoutConstraint? Can anyone please help?

+3


source to share


3 answers


MASConstraint

is an abstract class and can potentially represent more than one class at NSLayoutConstraints

once, so it is not quite as applicable to get a reference as one might expect.

That being said, you can use the MASConstraint setOffset

: method to change the underlying NSLayoutConstraint layout constant that suits many animation use cases. As shown below:



MASConstraint *widthConstraint;
[POPSpringAnimation animationWithPropertyNamed:@"offset"];
animation.springBounciness = 8;
[widthConstraint pop_addAnimation:animation forKey:@"myAnimation"];

      

While looking for any alternative, I came across this thread with answers from the author himself to a similar problem.

+3


source


See "MSSPopMasonry" on github



A Using Freemasonry with the Facebook Pop Framework

0


source


There is a good tool that combines pop and Freemasonry called MSSPopMasonry: https://github.com/miklselsoe/MSSPopMasonry . With it (2 source files in total) you can create pop animations in MASContraint, so you don't need to convert MASContraint to NSLayoutConstraint, which is not supported in Freemasonry. Usage is simple:

// declare the constraint you want to animate with
MASConstraint *_signInScreenLeadingConstraint;
BOOL _isInSignUpScreen = NO;

// set constraint using Masonry
[view mas_makeConstraints:^(MASConstraintMaker *make) {
    _signInScreenLeadingConstraint = make.left.equalTo(view.superview).with.offset(0);
    make.top.and.bottom.equalTo(view.superview).with.offset(0);
    make.width.equalTo(view.superview).with.offset(0);
}];

// animate by pop
POPBasicAnimation *exchangeAnimation = [POPBasicAnimation easeInAnimation];
exchangeAnimation.property = [POPAnimatableProperty mas_offsetProperty];
exchangeAnimation.duration = 0.2f;
exchangeAnimation.toValue = _isInSignUpScreen ? @(0) : @(200);
[exchangeAnimation setCompletionBlock:^(POPAnimation *anim, BOOL finished) {
    _isInSignUpScreen = !_isInSignUpScreen;
}];
[_signInScreenLeadingConstraint pop_addAnimation:exchangeAnimation forKey:@"animation"];

      

Thanks to the author of MSSPopMasonry :)

0


source







All Articles