2014-06-16 153 views
0

我忙着UIViewControllers之間的自定義動畫化的轉變,我喜歡UIView的跳躍,然後填寫類似下面屏幕截圖空間:如何創建自定義計時功能?

enter image description here

現在還沒有一個「選項」我可以創造這樣的效果。現在我可以創建一個關鍵幀動畫,頂部有一個關鍵點,中間有一個關鍵點,但這不會讓人覺得很自然,它會感覺到機器人。

如何解決這個問題?

SOURCE(SO FAR)

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext 
{ 
    UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 
    UIViewController *toVC  = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; 
    UIView    *container = [transitionContext containerView]; 

    if ([fromVC isEqual:self]) 
    { 
     [_activeCardView.superview bringSubviewToFront:_activeCardView]; 

     [UIView animateKeyframesWithDuration:[self transitionDuration:transitionContext] 
             delay:0.0 
            options:UIViewKeyframeAnimationOptionCalculationModeCubic 
            animations:^{ 
             [_activeCardView setFrame:CGRectMake(0.0, 0.0, toVC.view.bounds.size.width, toVC.view.bounds.size.height)]; 
            } 
            completion:^(BOOL finished){ 
             [container addSubview:toVC.view]; 
             [transitionContext completeTransition:YES]; 
            }]; 
    } 
    else 
    { 
     [container addSubview:toVC.view]; 

     [UIView animateWithDuration:[self transitionDuration:transitionContext] 
         animations:^{ 
          [_activeCardView setFrame:_basicCardFrame]; 
         } 
         completion:^(BOOL finished){ 
          [transitionContext completeTransition:YES]; 
         }]; 
    } 
} 

回答

0

爲了順利 '跳' 的動畫,你可以只鏈中的兩個動畫與 'EaseInOut' 曲線。

[UIView animateWithDuration:<DURATION>/2 delay:<DELAY> options:UIViewAnimationOptionCurveEaseInOut animations:^(void) { 
     //move view up 
    }completion:^(BOOL finished) { 
     [UIView animateWithDuration:<DURATION>/2 delay:<DELAY> options:UIViewAnimationOptionCurveEaseInOut animations:^(void) { 
      //move view down 
     }completion:NULL]; 
    }]; 
+0

這可能工作,使動畫緩解和緩解可能會給彎曲加速度的錯覺。我會去嘗試一下。 – Mark