Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

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")

    }

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top