Autolayout and Facebook Pop
Asked Answered
M

4

7

Is there currently a way to use the Facebook Pop framework with auto-layout or do you have to use springs and struts? I keep reading that it is possible, but I don't know what the syntax is to be able to animate a view's top constraint.

Mcbrayer answered 31/7, 2014 at 20:21 Comment(1)
I am also trying to figure this out. Currently if I pop animate anything, the existing constraints are not adhered.Imperfective
M
21

In this case you want to animate an NSLayoutConstraint you can do the following with POP and it will animate the constraint. Note that the POPSpringAnimation is being added to the constraint itself.

NSLayoutConstraint *constraint = // this is an NSLayoutConstraint that is applied to some view

POPSpringAnimation *layoutAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayoutConstraintConstant];
layoutAnimation.springSpeed = 20.0f;
layoutAnimation.springBounciness = 15.0f;
layoutAnimation.toValue = @(value to go too);
[constraint pop_addAnimation:layoutAnimation forKey:@"detailsContainerWidthAnimate"];

The main property to use is the kPOPLayoutConstraintConstant as shown above. So if you want to do it on auto layout constraints you can use this constraint property.

Working with scale and other properties also works with AutoLayout so you should have no issues with getting POP to work with AutoLayout.

Murtagh answered 24/9, 2014 at 22:5 Comment(1)
I believe the question is not, how to animate a layout constraint, but rather. How to pop animate something without breaking existing autolayout configurations (or aka, how to have all the autolayout relationships update?). Thank youImperfective
C
1

The proper way to implement pop animation with autolayout is to initialize translatesAutoresizingMaskIntoConstraints

Cryptonymous answered 10/2, 2016 at 0:40 Comment(0)
O
1

In Swift-3 the code looks like this;' Assume that self.menuFooterConstant is the reference of UI constraint on the Storyboard.

        if let anim = POPSpringAnimation(propertyNamed: kPOPLayoutConstraintConstant) {
        anim.toValue = 142
        anim.springSpeed = 20
        anim.springBounciness = 15
        self.menuFooterConstant.pop_add(anim, forKey: "animationForTrendfooter")

    }
Opheliaophelie answered 2/8, 2017 at 19:40 Comment(0)
H
0

You can directly animate the constraints. With POP just use the kPOPLayoutConstraintConstant property name. Setup your animation and add it to the constraint itself.

If you don't want to add a animation to the constraint itself you should keep in mind the following:

Remember to Update View Constraints as Part of Your Animation

If you are using constraint-based layout rules to manage the position of your views, you must remove any constraints that might interfere with an animation as part of configuring that animation. Constraints affect any changes you make to the position or size of a view. They also affect the relationships between the view and its child views. If you are animating changes to any of those items, you can remove the constraints, make the change, and then apply whatever new constraints are needed.

*from Apple Docs

Helgoland answered 15/2, 2015 at 12:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.