2016-11-11 10 views
0

カスタムトランジションでカスタムポップアップを実装しようとしていますが、デリゲートメソッドがまったく呼び出されていません。これは私の移行デリゲートです:UIViewControllerTransitioningDelegateメソッドが呼び出されていません

public final class ModalTransitioningDelegate: NSObject, UIViewControllerTransitioningDelegate { 

    public func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? { 
     let controller = ModalPresentationController(presentedViewController: presented, presenting: presenting) 

     return controller 
    } 

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

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

これは私のポップアップビューコントローラである:

@IBAction func test(_ sender: Any) { 
    let popup = UIStoryboard(name: "Popups", bundle: nil).instantiateInitialViewController() as! StopWorkoutViewController 
    present(popup, animated: true, completion: nil) 
} 

そして、これはIBのビューコントローラです:

class StopWorkoutViewController: UIViewController { 

    required init?(coder aDecoder: NSCoder) { 
     super.init(coder: aDecoder) 
     commonInit() 
    } 

    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { 
     super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) 
     commonInit() 
    } 

    func commonInit() { 

     let transitioner = ModalTransitioningDelegate() 
     modalPresentationStyle = .custom 
     transitioningDelegate = transitioner 
    } 
} 

これは私がポップアップを提示する方法であります:

Popup ViewController

ポップアップが表示されますが、全画面表示されます。

答えて

1

あなたがStopWorkoutViewController。あなたの推移をアニメーション化しようとしているので、これは

func commonInit() { 

     let transitioner = ModalTransitioningDelegate() 
     modalPresentationStyle = .custom 
     transitioningDelegate = transitioner 
    } 

間違っているが

@IBAction func test(_ sender: Any) { 
    let transitioner = ModalTransitioningDelegate() 
    let popup = UIStoryboard(name: "Popups", bundle: nil).instantiateInitialViewController() as! StopWorkoutViewController 
    popup.transitioningDelegate = transitioner 
    present(popup, animated: true, completion: nil) 
} 
1

として遷移デリゲートを設定する必要がある問題は、transitioningDelegateが弱い性質であるということですそのクラスに割り当てるクラスは、移行が実行される前に解放されています。デバッガでこれをキャッチする方法の例については、私の答えhereを参照してください。

関連する問題