2014-09-01 2 views
7

я смог оживить изменение ограничения с помощьюАнимация ограничений с помощью Facebook pop?

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

Но я был под впечатлением, что это также может быть сделано с использованием библиотеки POP Facebook. Может ли кто-нибудь указать мне в правильном направлении, чтобы узнать, как это сделать?

Спасибо

ответ

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

что, если вы хотите на самом деле оживить удаление и добавление ограничений? –

+0

Возможно, вам не нужна структура POP, но вместо этого используйте стандартные методы анимации 'UIView', добавляя и удаляя ограничения, а затем вызывающие setLayoutIfNeeded в блоке анимации для метода UIView' animateWith – darren102

+0

интересны, возможно, решение состоит в анимировании просмотр в и после завершения добавить ограничения. Спасибо за помощь :) –

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!!"); 
     } 
    } 
Смежные вопросы