为了在全视图中提供交互弹出手势,我在控制器中使用了UIPanGestureRecognizer,我们可以从视图控制器的任何位置向右滑动以弹出控制器,而不是使用默认的NavigationController弹出手势。
当我在视图中打开键盘时使用手势,键盘也会被关闭(这种情况在使用默认的NavigationController弹出手势时不会发生),看起来很奇怪。
如何在使用自定义的弹出转场时防止键盘关闭视图控制器。
当我在视图中打开键盘时使用手势,键盘也会被关闭(这种情况在使用默认的NavigationController弹出手势时不会发生),看起来很奇怪。
func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
if operation == .pop {
return PopControllerTransition()//My transition
}
return nil
}
如何在使用自定义的弹出转场时防止键盘关闭视图控制器。
//transition code
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let containerView = transitionContext.containerView
let fromController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from)!
let toController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to)!
toController.view.transform = CGAffineTransform(translationX: -(toController.view.bounds.width/3), y: 0)
containerView.insertSubview(toController.view, belowSubview: fromController.view)
let view = GradientView(frame: containerView.frame)
view.horizontal = true
view.backgroundColor = UIColor.clear
view.transform = CGAffineTransform(translationX: -toController.view.bounds.width, y: 0)
view.gradientLayer.colors = [UIColor(white: 0.0, alpha: 0.2).cgColor, UIColor(white: 0.0, alpha: 0.5).cgColor]
containerView.insertSubview(view, belowSubview: fromController.view)
let duration = transitionDuration(using: transitionContext)
UIView.animate(withDuration: duration, animations: {
toController.view.transform = .identity
fromController.view.transform = CGAffineTransform(translationX: fromController.view.bounds.width, y: 0)
view.transform = .identity
view.alpha = 0.0
}) { (finish) in
if !transitionContext.transitionWasCancelled {
fromController.view.removeFromSuperview()
}
view.removeFromSuperview()
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
}
}