使用Facebook pop进行动画约束?

时间:2014-09-01 19:43:09

标签: ios facebook-pop

我能够使用

为约束更改设置动画
[UIView animateWithDuration:0.5
                      delay:0.5
     usingSpringWithDamping:0.7
      initialSpringVelocity:0.7
                    options:0
                 animations:^{
                     [self.closeButton layoutIfNeeded];
                 } completion:NULL];

但我的印象是,这也可以使用Facebook POP库完成。谁能指出我找到正确的方向?

谢谢

2 个答案:

答案 0 :(得分:19)

在这种情况下,您希望为NSLayoutConstraint设置动画,您可以使用POP执行以下操作,它将为约束设置动画。

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,如上所示。

答案 1 :(得分:0)

这是使用弹簧动画的另一个例子......

    -(void)shakeViewConstraint:(NSLayoutConstraint*)constraint{

        POPSpringAnimation *springStart = [POPSpringAnimation animationWithPropertyNamed:kPOPLayoutConstraintConstant];

        springStart.springSpeed = 0.5;
        springStart.springBounciness = 0.3;
        springStart.fromValue = @(50);
        springStart.toValue = @(25);
        springStart.velocity = @600;
        springStart.delegate = self; //Using Delegates as handlers

        [constraint pop_addAnimation:springStart forKey:@"animationUniquekey"];

        //Using Blocks as handlers
        [springStart setCompletionBlock:^(POPAnimation* animation, BOOL finished) {

            if (finished)
                [constraint pop_removeAnimationForKey:@"animationUniquekey"];
        }];
    }

    #pragma mark - POP Animation Delegates

    -(void)pop_animationDidStart:(POPAnimation *)anim{

        //NSLog(@"POP ANIM STARTED!!");

    }

    -(void)pop_animationDidStop:(POPAnimation *)anim finished:(BOOL)finished{

        //NSLog(@"POP ANIM STOPPED!!");

        if (finished) {

            //NSLog(@"POP ANIM FINISHED!!");
        }
    }