目前有没有办法使用 脸书流行 具有自动布局的框架还是必须使用 spring 和 struts?我一直读到这是可能的,但我不知道能够为视图的顶部约束设置动画的语法是什么。

有帮助吗?

解决方案

在这种情况下,您想要动画NSLayOutConstraint您可以使用POP执行以下操作,并将其动画约束。请注意,popspringanimation正在添加到约束本身

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"];
.

使用的主要属性是kpoplayoutconstraintConstant,如上所示。因此,如果要在自动布局约束上执行此操作,则可以使用此约束属性。

使用Scale和其他属性也与Autolayout一起使用,因此您应该没有任何问题来使用Autolayout使用。

其他提示

实现流行动画的正确方法 autolayout 是初始化 translatesAutoresizingMaskIntoConstraints

在swift-3中,代码看起来像这样;'假设self.menufootononstant是故事板上UI约束的引用。

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

    }
.

您可以直接动画约束。使用pop只使用 kpoplayoutconstraintConstant 属性名称。设置动画并将其添加到约束本身。

如果您不想将动画添加到约束本身,您应该记住以下内容:

请记住以将视图约束更新为动画的一部分

如果您使用的基于约束的布局规则来管理您的视图的位置,则必须删除可能会在动画中干扰动画的任何约束,作为配置该动画的一部分。约束会影响您对视图的位置或大小的任何更改。它们还会影响视图与其儿童观点之间的关系。如果您对任何这些项目的更改设置了更改,则可以删除约束,进行更改,然后应用任何需要的新约束。

*来自Apple Docs

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top