要在全视图中提供交互弹出手势,我的控制器中有一个UIPanGestureRecognizer,我们可以从左向右滑动视图控制器中的任何位置以弹出控制器,而不是使用默认的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
}
如何在使用我的自定义弹出过渡弹出viewController时阻止键盘解除。
//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)
}
}
答案 0 :(得分:0)
因此,我注意到iOS 13上的键盘转换与iOS 12上的键盘转换不同,因此我必须像这样手动进行操作:
let animations: () -> Void = {
fromView.frame.origin.x += fromView.bounds.width
toView.frame.origin.x += fromView.bounds.width
// Keyboard behavior changed on iOS 13. It dismisses ignoring transition
// so need to fix that manually.
if #available(iOS 13.0, *) {
let keyboardWindow = UIApplication.shared.windows
.first { String(describing: type(of: $0)) == "UIRemoteKeyboardWindow" }
if let keyboardWindow = keyboardWindow, let keyboardImage = keyboardWindow.getImage() {
let imageView = UIImageView(image: keyboardImage)
keyboardWindow.addSubview(imageView)
keyboardWindow.frame.origin.x += keyboardWindow.frame.width
}
}
}