2016-10-11 4 views
1

私はこのプロジェクトを最近ダウンロードし、最新の迅速な構文に変換しました。条件バインディングの初期設定には、 "UIView"ではなく、オプションの型が必要です

:ここ

let containerView = transitionContext.containerView 

は完全なコードです:私はUIViewの 『

エラーがライン上で発生している「結合条件付きの初期化子は、オプションの種類ではなく持っている必要があります』というエラーを取得し続ける理由を私は理解できません

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { 
    guard 
     let fromVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from), 
     let toVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to), 
     let containerView = transitionContext.containerView 
     else { 
      return 

    } 

    containerView.insertSubview(toVC.view, belowSubview: fromVC.view) 

    let screenBounds = UIScreen.main.bounds 
    let bottomLeftCorner = CGPoint(x: 0, y: screenBounds.height) 
    let finalFrame = CGRect(origin: bottomLeftCorner, size: screenBounds.size) 

    UIView.animate(
     withDuration: transitionDuration(using: transitionContext), 
     animations: { 
      fromVC.view.frame = finalFrame 
     }, 
     completion: { _ in 
      transitionContext.completeTransition(!transitionContext.transitionWasCancelled) 
     } 
    ) 
} 
+2

ガードステートメントの 'let containerView = transitionContext.containerView'を' containerView.insertSubview(toVC.view、belowSubview:fromVC.view) 'の上に置いてください。 –

答えて

0

containerViewプロパティはオプションのタイプではないからであるあなたがここに見ることができるように(UIViewControllerContextTransitioingのドキュメント(コマンド+ LMB)から取られている):。

... 
public protocol UIViewControllerContextTransitioning : NSObjectProtocol { 


    // The view in which the animated transition should take place. 

    @available(iOS 2.0, *) 
    public var containerView: UIView { get } 
... 

guardステートメントの後に誤った行を配置することができます。

関連する問題