Open
Description
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?
Metadata
Assignees
Labels
No labels