2013-09-16 5 views
11

私は現在のカスタムを作成してトランジションを終了し、いくつか問題があります。私がしたいことは、iOS 7でこの涼しい深いアニメーションを繰り返すことです(私たちがいくつかのアプリケーションを開いたり閉じたりするとき)。 私には第1コントローラと第2コントローラがあります。すべてのアニメーションはFirst Controller(UIViewControllerTransitioningDelegateおよびUIViewControllerAnimatedTransitioningをサポート)にあります。だから私はちょうどチェックしている:それが提示されている場合 - 私は1つのアニメーション(1番目と2番目のビューを拡大)、解雇されている場合 - 私は別のアニメーション(1番目と2番目のビューを縮小している)をやっている。現在のアニメーションは問題なく動作しますが、アニメーションを終了すると問題が発生します。何らかの理由で、私が2番目のコントローラー(UINavigationController)を縮小しているときに、その背後に黒い背景が表示されます(スケーリングが縮小されている間に最初のコントローラーを見たいので間違っています)。ファーストコントローラーのコードです。ios 7カスタムプレゼントとトランジションを外します

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext { 
    UIView *transitionView = [transitionContext containerView]; 

    id toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; 
    id fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 

    BOOL isPresenting; 

    isPresenting = [toViewController isKindOfClass:[UINavigationController class]]; 

    UINavigationController *navigator = isPresenting ? toViewController : fromViewController; 

    if (isPresenting) { 
     [transitionView addSubview:navigator.view]; 
     navigator.view.transform = CGAffineTransformMakeScale(0.1, 0.1); 
     navigator.view.alpha = 0; 
    } 

    navigator.view.center = self.startButton.center; 

    void(^AnimationBlock)(void) =^{ 
     if (isPresenting) { 
      navigator.view.transform = CGAffineTransformMakeScale(1, 1); 
      self.view.transform = CGAffineTransformMakeScale(4, 4); 
      navigator.view.alpha = 1; 
      self.startButton.alpha = 0; 
     } else { 
      navigator.view.transform = CGAffineTransformMakeScale(0.1, 0.1); 
      self.view.transform = CGAffineTransformMakeScale(1, 1); 
      navigator.view.alpha = 0; 
      self.startButton.alpha = 1; 
     } 
    }; 

    [UIView animateWithDuration:1 
          delay:0.0f 
     usingSpringWithDamping:50.0 
      initialSpringVelocity:4 
         options:UIViewAnimationOptionLayoutSubviews 
        animations:^{ 
         AnimationBlock(); 
    } completion:^(BOOL finished) { 
     [transitionContext completeTransition:YES]; 
     if (!isPresenting) { 
      [navigator.view removeFromSuperview]; 
     } 
    }]; 
} 

- (void)completeTransitionInContext:(id<UIViewControllerContextTransitioning>)transitionContext{ 
    [transitionContext completeTransition:YES]; 
} 


- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext{ 
    return 1; 
} 


- (id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source { 
    return self; 
} 

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed { 
    return self; 
} 

いくつかのコードやスクリーンを追加する必要があるかどうか教えてください。 ありがとうございます!

+0

iOS 7 APIは公の利用可能性(18 sept)までNDAの下にあります – Vinzzz

+0

私は非常に似た問題があり、iOS7 APIはもはやNDAの下にありません...解決方法を教えてください。ありがとう! – veducm

+0

まだ回答がわからない:( –

答えて

3

私は存在するための2つの別々のAnimationControllerクラスを使用してアニメーションを閉じ、自分の親のViewController内UIViewControllerTransitioningDelegate(animationControllerForPresentedControlleranimationControllerForDismissedController)を実装することをお勧めだと思います。

AnimationControllerをサブクラスNSObjectにサブクラス化し、そこにUIViewControllerAnimatedTransitioningを実装してください。

希望します。

10

あなたは現在移行が完了した後、ウィンドウの階層にfromVCを維持したい場合は、それを提示する前にtoVCにmodalPresentationStyle = UIModalPresentationCustomを設定する必要があります。

WWDCセッション218のサンプルコードの実装:ビューコントローラを使用したカスタムトランジションを参照してください。 「オプション」をクリックすると、このタイプの遷移が表示されます。関連するコードSOLViewController.m prepareForSegueにありますし、SOLOptionsTransitionAnimator.m

https://github.com/soleares/SOLPresentingFun

6

カスタムVCを提示すると、あなたが使用する必要があります。 vc.modalPresentationStyle = UIModalPresentationCustom; しかし、あなたは vc.modalTransitionStyle = UIModalPresentationCustom; に間違って入力した場合は取得します黒い背景がカスタムVCの背後にあります。

+1

投稿用のThanx。時間を節約できました。 – smileBot

関連する問題