2017-04-18 18 views
0

simpel 전환을 수행하고 있지만 전화를받지 못했습니다. 내가 여기에서 놓친 것을 얻지 못하고 있습니다. 누구든지 나를 도와 줄 수 있습니다. 오류나 경고가 없습니다.UIViewControllerAnimated 전환이 실행되지 않음

애니메이션 클래스 - :

import UIKit 

class ItemsTableViewController: UITableViewController,UIViewControllerTransitioningDelegate { 

    override func viewDidLoad() { 
     super.viewDidLoad() 

    } 
    let customPresentAnimationController = CustomPresentAnimationController() 

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
     if segue.identifier == "showAction" { 
      let toViewController = segue.destination as! ActionViewController 
      toViewController.transitioningDelegate = self 
     } 
    } 
    override func numberOfSections(in tableView: UITableView) -> Int { 
     return 1 
    } 

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return 5 
    } 

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "ItemCell", for: indexPath) as UITableViewCell 
     cell.textLabel?.text = "Item 0\(indexPath.row + 1)" 
     return cell 
    } 

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

} 

ToViewcontroller- : 뷰 컨트롤러 -에서

import UIKit 

class CustomPresentAnimationController: NSObject,UIViewControllerAnimatedTransitioning { 

    public func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval 
    { 
     return 2.5 
    } 
    // This method can only be a nop if the transition is interactive and not a percentDriven interactive transition. 
    public func animateTransition(using transitionContext: UIViewControllerContextTransitioning) 

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

     UIView.animate(withDuration: transitionDuration(using: transitionContext),delay: 0.1,options: UIViewAnimationOptions.curveEaseIn,animations: {() -> Void in 
      fromViewController?.view.alpha = 0.5 
      toViewController?.view.frame = finalViewcontroller 
     },completion: { (finished) -> Void in 

      transitionContext.completeTransition(true) 
      fromViewController?.view.alpha = 1.0 
     }) 
    } 


} 

당신의 복사/붙여 넣기 스위프트 2 버전을 가지고있는 것처럼

import UIKit 

class ActionViewController: UIViewController { 

    @IBAction func dismiss(_ sender: UIButton) { 
     self.dismiss(animated: true, completion: nil) 
    } 

} 

답변

1

이 보이는 메소드와 이제 서명이 다릅니다 :

func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
    return Transition() 
} 

func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
    return Transition() 
} 

EDIT : 전환의 새로운 인스턴스를 반환하고 상단에 let을 없애는 것이 가장 좋습니다.

+0

도움 주셔서 감사합니다. –