2014-09-01 95 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!!"); 
     } 
    }