Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue when presenting a UINavigationController. #9

Open
junestchick opened this issue Jun 12, 2019 · 0 comments
Open

Issue when presenting a UINavigationController. #9

junestchick opened this issue Jun 12, 2019 · 0 comments

Comments

@junestchick
Copy link

junestchick commented Jun 12, 2019

Hi, i tried this code
let navi = UINavigationController(rootViewController: ModalViewController()) navi.transitioningDelegate = self.transitionManager self.present(navi, animated: true, completion: nil)

with my own custom animation:
`class ScaleTransitionAnimation: TransitionManagerAnimation {
private weak var panningViewController: UIViewController?

override func transition(
    container: UIView,
    fromViewController: UIViewController,
    toViewController: UIViewController,
    isDismissing: Bool,
    duration: TimeInterval,
    completion: @escaping () -> Void) {
    if isDismissing {
        closeAnimation(
            container: container,
            fromViewController: fromViewController,
            toViewController: toViewController,
            duration: duration,
            completion: completion)
    } else {
        openAnimation(
            container: container,
            fromViewController: fromViewController,
            toViewController: toViewController,
            duration: duration,
            completion: completion)
    }
}

func openAnimation (
    container: UIView,
    fromViewController: UIViewController,
    toViewController: UIViewController,
    duration: TimeInterval,
    completion: @escaping () -> Void) {
    
    container.addSubview(toViewController.view)
    toViewController.view.top = fromViewController.view.bottom
    toViewController.view.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(handlePan(pan:))))
    panningViewController = toViewController
    
    UIView.animate(
        withDuration: duration,
        animations: {
            toViewController.view.top = 0
    },
        completion: { finished in
            completion()
    })
}

func closeAnimation (
    container: UIView,
    fromViewController: UIViewController,
    toViewController: UIViewController,
    duration: TimeInterval,
    completion: @escaping () -> Void) {
    
    container.addSubview(toViewController.view)
    container.bringSubviewToFront(fromViewController.view)
    
    UIView.animate(
        withDuration: duration,
        animations: {
            fromViewController.view.frame = CGRect(x: 60, y: 400, width: 120, height: 120)
    },
        completion: { finished in
            completion()
    })
}

@objc func handlePan(pan: UIPanGestureRecognizer) {
    let percent = pan.translation(in: pan.view!).y / pan.view!.bounds.size.height
    switch pan.state {
    case .began:
        interactionTransitionController = UIPercentDrivenInteractiveTransition()
        panningViewController?.dismiss(animated: true, completion: {
            self.interactionTransitionController?.finish()
        })
    case .changed:
        interactionTransitionController!.update(percent)
    case .ended:
        if percent > 0.5 {
            interactionTransitionController!.finish()
            panningViewController = nil
        } else {
            interactionTransitionController!.cancel()
        }
        interactionTransitionController = nil
    default:
        return
    }
}

}`
but the transition is not correct, presenting a UIViewController is oke. Can you check that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant