2014-09-01 54 views
7

我能够使用动画使用Facebook弹出动画约束?

[UIView animateWithDuration:0.5 
         delay:0.5 
    usingSpringWithDamping:0.7 
     initialSpringVelocity:0.7 
        options:0 
       animations:^{ 
        [self.closeButton layoutIfNeeded]; 
       } completion:NULL]; 

约束变化,但我的印象是,这可能也使用Facebook POP库来完成。任何人都可以指出我正确的方向来了解如何?

谢谢

回答

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。

+0

如果你想实际动画删除和添加约束? – 2015-01-14 13:24:31

+0

您可能不想要POP框架,而是使用标准的'UIView'动画方法,通过添加和删除约束,然后调用动画块中的setLayoutIfNeeded,以获得有趣的'UIView' animateWith方法 – darren102 2015-01-14 15:25:27

+0

,可能解决方案是动画视图在完成时添加约束。感谢您的帮助:) – 2015-01-14 15:26:42

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!!"); 
     } 
    }