2016-10-09 9 views
1

私は自分のアプリケーションのカスタムトランジションを作成していますが、コピー先のビューのスナップショットを作成しようとすると、常に空の白い四角形として表示されます。私はこれがカスタムpush移行であり、ビューのモーダルプレゼンテーションではないことに注意してください。モーダルを提示すると、スナップショットが機能しているように見えます。これはカスタムpush/pop遷移の通常の動作ですか?次のようにカスタムUIViewControllerトランジションのUIViewスナップショット

私が書いたコードは次のとおりです。それがレンダリングされる前に

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { 
    guard let toViewController = transitionContext.viewController(forKey: .to) as? CultureViewController else { 
     return 
    } 

    let containerView = transitionContext.containerView 
    let finalFrame = transitionContext.finalFrame(for: toViewController) 

    let snapshot = toViewController.view.snapshotView(afterScreenUpdates: true) 
    snapshot?.frame = UIScreen.main.bounds 
    containerView.addSubview(snapshot!) 

    toViewController.view.transform = CGAffineTransform(translationX: 0, y: toViewController.view.bounds.height) 
    //containerView.addSubview(toViewController.view) 

    let duration = transitionDuration(using: transitionContext) 
    UIView.animateKeyframes(withDuration: duration, delay: 0, options: .calculationModeCubic, animations: { 
     UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 1, animations: { 
      toViewController.view.frame = finalFrame 
     }) 
    }, completion: { _ in 
     transitionContext.completeTransition(!transitionContext.transitionWasCancelled) 
    }) 
} 
+0

このスニペットを含むクラス全体を投稿することができますか。 –

+0

これを理解したことがありますか?まだこの正確な問題を見ている。 – Danny

答えて

1

は、ビューのスナップショットを撮るあなたはcontainerView.addSubview(toViewController.view)を呼び出す前に、このような遷移の場合と、空白のビューを返し、 UIView's documentation

まだ表示されていない可能性があるため、現在のビューがまだレンダリングされていない場合、スナップショットビューには表示されたコンテンツがありません。

関連する問題