5

Tôi stumped bởi một nhiệm vụ rất đơn giản, tôi muốn có một hình ảnh động UIView để làm dễ dàng trong/dễ dàng ra nhưng nó luôn luôn là tuyến tính mặc dù sử dụng animationOption chính xác.UIView đường cong hoạt hình không hoạt động easinout

Đây là mã mà tất cả các tài khoản nên hoạt động, nó được đặt trong lớp UIViewControllerAnimatedTransitioning nhưng tôi có cùng một vấn đề trong lớp phân biệt tùy chỉnh trước đó;

[UIView animateWithDuration:0.4f delay:0.0f options:UIViewAnimationOptionCurveEaseInOut animations:^(void) { 

     self.dimView.alpha = 1.0; 
     self.imageView.frame = self.destinationRect; 

    } completion:^(BOOL finished) { 

     [self.imageView removeFromSuperview]; 
     [self.dimView removeFromSuperview]; 

     [transitionContext completeTransition:YES]; 

    }]; 

Tuy nhiên, hoạt ảnh mùa xuân có mã sau hoạt động mặc dù tôi không muốn làm điều này.

[UIView animateWithDuration:0.8f delay:0 usingSpringWithDamping:0.7f initialSpringVelocity:2.0f options:UIViewAnimationOptionCurveEaseInOut animations:^(void) { 

     self.dimView.alpha = 1.0; 
     self.imageView.frame = self.destinationRect; 

    } completion:^(BOOL finished){ 

     [self.imageView removeFromSuperview]; 
     [self.dimView removeFromSuperview]; 

     [transitionContext completeTransition:YES]; 

    }]; 

Tôi nhận được cùng một hành vi trên trình mô phỏng và trên thiết bị thử nghiệm iPad2. Tôi có làm gì sai không? Có vấn đề với hoạt ảnh hoặc giá trị khung hoặc alpha không?

Trả lời

3

Bạn có thể thử này instead.-

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationBeginsFromCurrentState:YES]; 
[UIView setAnimationDuration:0.4f]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
[UIView setAnimationDelegate:self]; 
[UIView setAnimationDidStopSelector:@selector(animationDidStop)]; 

self.dimView.alpha = 1.0; 
self.imageView.frame = self.destinationRect; 

[UIView commitAnimations]; 

- (void) animationDidStop { 
    [self.imageView removeFromSuperview]; 
    [self.dimView removeFromSuperview]; 
    [transitionContext completeTransition:YES]; 
} 

Hy vọng nó giúp.

+0

Cảm ơn ssantos. Lúc đầu, tôi nghĩ rằng nó đã làm các trick nhưng đôi mắt của tôi đã lừa tôi. Vẫn chắc chắn tuyến tính. Rất lạ và khó chịu. –

+0

Mmh thực sự kỳ lạ, có thể khoảng cách quá nhỏ để nhận thấy sự khác biệt? Tôi muốn thử một hoạt hình 'lớn' với 'animationCurves' khác nhau chỉ trong trường hợp. – ssantos

1

Bạn có thể sử dụng các mục sau:

[tự chuyển đổi: bên trái]; // Gọi theo yêu cầu

enum animationFrom { 
    top, 
    bottom, 
    left, 
    right 
}; 

- (void)transition:(NSUInteger)index { 
    CATransition *tr=[CATransition animation]; 
    tr.duration=0.45; 
    tr.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
    tr.type=kCATransitionPush; 
    tr.delegate=self; 
    switch (index) { 
     case top: 
      tr.subtype=kCATransitionFromBottom; 
      break; 
     case bottom: 
      tr.subtype=kCATransitionFromTop; 
      break; 
     case left: 
      tr.subtype=kCATransitionFromRight; 
      break; 
     case right: 
      tr.subtype=kCATransitionFromLeft; 
      break; 
     default: 
      break; 
    } 
    [self.view.layer addAnimation:tr forKey:nil]; 
} 
1

Tùy chọn đường cong hoạt ảnh mặc định là UIViewAnimationOptionCurveEaseInOut, vì vậy bạn không cần chỉ định tùy chọn này. Đó là UIViewAnimationOptionCurveLinear mà bạn phải rõ ràng.

Bạn có chắc đường cong hoạt hình của mình là tuyến tính không? Thử làm động hai bên chế độ xem ở bên cạnh, với thời lượng hoạt ảnh được đặt thành vài giây.