2014-09-01 16 views
7

tôi đã có thể để animate một sự thay đổi hạn chế sử dụngAnimate ràng buộc bằng cách sử dụng Facebook pop?

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

Nhưng tôi đã theo ấn tượng rằng điều này cũng có thể được thực hiện bằng cách sử dụng thư viện POP Facebook. Bất cứ ai có thể chỉ cho tôi đi đúng hướng để tìm hiểu làm thế nào?

Cảm ơn bạn

Trả lời

19

Trong trường hợp này bạn muốn để animate một NSLayoutConstraint bạn có thể làm như sau với POP và nó sẽ animate hạn chế.

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

Thuộc tính chính để sử dụng là kPOPLayoutConstraintConstant như minh họa ở trên.

+0

gì nếu bạn muốn thực sự sinh động loại bỏ và thêm một hạn chế? –

+0

Bạn có thể sẽ không muốn khung POP nhưng thay vào đó sử dụng phương thức animate 'UIView' chuẩn bằng cách thêm và loại bỏ các ràng buộc sau đó gọi setLayoutIfNeeded trong khối hoạt ảnh cho phương thức' UIView' animateWith – darren102

+0

thú vị, có lẽ giải pháp là làm động xem trong và trên hoàn thành thêm ràng buộc. Cảm ơn sự giúp đỡ :) –

0

Dưới đây là một ví dụ khác sử dụng hình ảnh động mùa xuân ...

-(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!!"); 
     } 
    } 
Các vấn đề liên quan