2016-10-08 7 views
-1

私はこれに続いてカスタムビュートランジションを作成しようとしています。tutorial。カスタム移行が機能しません。しかし、ここに私のコードカスタムビューコントローラーのトランジションxcode8

class ItemsTableViewController: UITableViewController, UIViewControllerTransitioningDelegate { 

let customPresentAnimationController = CustomPresentAnimationController() 

// viewDidLoad and TableView methods 

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    if segue.identifier == "showAction" { 
     let toViewController = segue.destination as UIViewController 
     toViewController.transitioningDelegate = self 
     toViewController.modalPresentationStyle = .custom 
    } 
} 

func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
    return customPresentAnimationController 
} 

}

とCustomPresentAnimationController

class CustomPresentAnimationController: NSObject, UIViewControllerAnimatedTransitioning { 

func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { 
    return 5 
} 

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { 

    let fromViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from)! 
    let toViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to)! 
    let finalFrameForVC = transitionContext.finalFrame(for: toViewController) 
    let containerView = transitionContext.containerView 
    let bounds = UIScreen.main.bounds 
    toViewController.view.frame = finalFrameForVC.offsetBy(dx: 0, dy: bounds.size.height) 
    containerView.addSubview(toViewController.view) 

    UIView.animate(withDuration: transitionDuration(using: transitionContext), delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.0, options: .curveLinear, animations: { 
     fromViewController.view.alpha = 0.5 
     toViewController.view.frame = finalFrameForVC 
     }, completion: { 
      finished in 
      transitionContext.completeTransition(true) 
      fromViewController.view.alpha = 1.0 
    }) 
} 

}

ためです。 animationControllerForPresentedControllerメソッドが呼び出されないという問題があります。 これを修正するにはどうすればよいですか? SWIFT 3において

答えて

0

func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
return customPresentAnimationController 
} 

func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
    return customPresentAnimationController 
} 
に置換されている方法
関連する問題